推送代码后,Pivotal Tracker 故事未更新

Pivotal tracker story is not getting updated after code push

我们有与 GitHub 集成的关键跟踪器,当我们使用故事 ID 提交时,它会使用提交消息更新故事状态来更新故事。

我们最近从 GitHub 迁移到 Team Foundation Server,但该集成不再有效。

似乎还没有 integration App 存在。

是否有程序化的方式来做到这一点?

创建名为 pre-push 的文件(不带任何扩展名)并将其放在存储库中的 ./.git/hooks/ 文件夹下。如果它是一个有效的回购协议,这个文件夹应该已经存在。在文件中复制粘贴以下代码。不要忘记替换以下代码中的 API 标记值 -

#!/usr/bin/env ruby
# encoding: UTF-8

require 'net/https'
require 'json'

class GitLogs
  attr_accessor :raw_log, :commit_data, :commit, :author, :message, :refs

  def initialize
    self.commit = 'Commit: ' + `git log -1 --pretty=format:%h`.force_encoding('utf-8')
    self.author = 'Author: ' + `git log -1 --pretty=format:%aN`.force_encoding('utf-8')
    self.message = 'Message: ' + `git log -1 --pretty=format:%s`.force_encoding('utf-8')
    self.refs = 'Refs: ' + `git log -1 --pretty=format:%d`.force_encoding('utf-8')

    # Example git formatted log output:
    #
    # Commit: 8872e8fe03a10238d7be84d78813874d79ce0c3d
    # Author: John Doe <john.doe@unknown.com>
    # Message: [#90743834] test new v5 hook addition
    # Refs:  (HEAD, feature/hook-test)

    parse!
    self
  end

  def parse!
    self.commit_data = GitLog.new(self.commit, self.author, self.message, self.refs)
  end

  def pivotal_sync!
    Pivotal.new(commit_data).send! if commit_has_story_id?
  end

  def commit_has_story_id?
    # somewhere between square brackets there has to be a hash followed by multiple digits
    !commit_data.message.scan(/\[*+\#(\d+)\D?(.*)\]/).empty?
  end

end

class GitLog
  attr_accessor :hash, :author, :message, :refs

  def initialize hash, author, message, refs
    self.hash     = hash
    self.author   = author
    self.refs     = refs
    self.message  = message

    updated_message
  end

  def updated_message
    return message
  end

  def to_json
    { source_commit:
      { commit_id:  self.hash,
        author:     self.author,
        message:    self.message,
      }
    }.to_json
  end
end

class Pivotal
  attr_accessor :git_log, :tracker_token

  BASE_URI = URI('https://www.pivotaltracker.com/')

  def initialize git_log
    self.git_log        = git_log
    self.tracker_token  = get_token
  end

  def get_token
    'YOUR APT TOKEN GOES HERE. CAN GET IT FROM https://www.pivotaltracker.com/profile'
  end

  def send!
    https = Net::HTTP.start(BASE_URI.host, 443, {
      use_ssl:      true,
      verify_mode:  OpenSSL::SSL::VERIFY_NONE
    })

    request = Net::HTTP::Post.new('/services/v5/source_commits')
    request['X-TrackerToken'] = tracker_token
    request['Content-type']   = 'application/json'
    request.body              = git_log.to_json

    response                  = https.request(request)
  end
end

GitLogs.new().pivotal_sync!