【问题标题】:Pivotal tracker story is not getting updated after code push代码推送后 Pivotal 跟踪器故事未更新
【发布时间】:2019-04-23 19:39:34
【问题描述】:

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

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

似乎还没有integration App 存在。

有没有程序化的方法?

【问题讨论】:

    标签: tfs githooks pivotaltracker


    【解决方案1】:

    创建名为pre-push(不带任何扩展名)的文件,并将其放在您的repo 内的./.git/hooks/ 文件夹下。如果它是一个有效的 repo,这个文件夹应该已经存在。复制粘贴以下代码到文件中。不要忘记替换以下代码中的 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!
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-06
      • 1970-01-01
      相关资源
      最近更新 更多