简体   繁体   English

如何自动化Pivotal Tracker和Github集成?

[英]How can I automate Pivotal Tracker & Github Integration?

Pivotal Tracker and Github have great integration: Once it's set up, each commit which is prefixed by the Pivotal Tracker ID will appear under the corresponding Pivotal Ticket automatically, for an example: Pivotal Tracker和Github具有很好的集成性:一旦设置完成,每个以Pivotal Tracker ID为前缀的提交将自动显示在相应的Pivotal Ticket下,例如:

git commit -am '[#1234567] my new changes'
git push origin

will add the comment 'my new changes' automatically to the 1234567 Pivotal Ticket among with the github commit link. 将使用github提交链接自动将评论“我的新更改”添加到1234567 Pivotal Ticket中。

However, it's easy to forget to add the ticket ID each time. 但是,每次都很容易忘记添加票证ID。 How could it be simplified / automated? 怎么可以简化/自动化?

The solution is to use Git-Hooks and feature branches. 解决方案是使用Git-Hooks和功能分支。 (The Github-flow is recommended). (建议使用Github-flow)。

You have to install this Git-Hook (copy a file to your local repository): 您必须安装此Git-Hook(将文件复制到本地存储库):

https://github.com/ktamas77/git_hooks https://github.com/ktamas77/git_hooks

Before you start working on a particular Pivotal Ticket, you create a branch prefixed with the Pivotal Tracker ID, for an example: 在开始处理特定Pivotal故障单之前,您需要创建一个以Pivotal Tracker ID为前缀的分支,例如:

git checkout 1234567_build_new_form

then add all your changes as you'd do normally: 然后像平常一样添加所有更改:

git commit -am 'form added'
git commit -am 'styles added'
git push origin

you'll see, the git hook script will automatically extract the Pivotal Tracker ID from the feature branch name and add it to the front of each comment. 你会看到,git hook脚本会自动从功能分支名称中提取Pivotal Tracker ID并将其添加到每个注释的前面。 You can still manually override it (with another ID) if you want. 如果需要,您仍然可以手动覆盖它(使用另一个ID)。

In this way you don't have to worry about adding the Pivotal ID manually for every single commit. 通过这种方式,您不必担心每次提交都手动添加Pivotal ID。 It also works with GUIS (such as GIT Tower) since these GUIs are using the standard GIT libraries / executables. 它也适用于GUIS(例如GIT Tower),因为这些GUI使用标准的GIT库/可执行文件。

Here's a simple shell version based on Tamas' solution. 这是一个基于Tamas解决方案的简单shell版本。 It takes the ID from the end of the branch name. 它从分支名称的末尾获取ID。

"my-feature-branch-12345678" => "My commit mssg [#12345678]". “my-feature-branch-12345678”=>“我的提交mssg [#12345678]”。

Move to .git/hooks/prepare-commit-msg and make it executable: 移动到.git / hooks / prepare-commit-msg并使其可执行:

#!/bin/bash
if story_id=`git branch | grep -oP '^\*.*\-\K[0-9]+$'`
then
  echo "[#$story_id]" >> "$1"
fi

Install the 'git-pivotal-tracker-integration' gem, https://github.com/nebhale/git-pivotal-tracker-integration 安装'git-pivotal-tracker-integration'gem, https://github.com/nebhale/git-pivotal-tracker-integration

It adds commands to git like start and finish to Git to automatically prefix branches and commits with the tracker story ID and it also posts your commit messages to tracker. 它向Git添加命令,如Git的开始和结束,自动为分支和提交添加跟踪器故事ID,并将提交消息发布到跟踪器。 When you call 'git start' it will pull master to make sure you are up to date, create a branch for you and start the story in tracker for you. 当你打电话给'git start'时,它会拉主人以确保你是最新的,为你创建一个分支,并为你在跟踪器中启动故事。 Do the work then call 'git finish' and it will merge your branch back in to master and update tracker. 然后工作然后调用'git finish',它会将你的分支合并回主控和更新跟踪器。

My teams are using git_tracker . 我的团队正在使用git_tracker Each developer must run 每个开发者必须运行

$ git tracker init

once for every project on Pivotal Tracker. 对于Pivotal Tracker上的每个项目都有一次。 Then they need to name each new branch with a special convention, suffixing it with the Pivotal Tracker story id. 然后,他们需要使用特殊约定命名每个新分支,并使用Pivotal Tracker故事ID作为后缀。 For instance: 例如:

$ git checkout -b the-great-feathure-123456789

where 123456789 would be the Pivotal Tracker story id. 其中123456789将成为Pivotal Tracker的故事ID。

And here you go, you'll automatically have each commit refering to the story. 在这里,你会自动让每个提交参考故事。 Bonus point, if you use GitHub to perform pull requests, you can ask reviewers who merge the story to add to the merge commit: 奖励点,如果您使用GitHub执行拉取请求,您可以要求合并故事的审阅者添加到合并提交:

[Fixes #123456789] ...

This way, you never have to click on the Finish button, GitHub will do it for you. 这样,您永远不必单击Finish按钮,GitHub将为您完成。

I am using a bookmarklet, which also sets the commit message from the story title. 我正在使用bookmarklet,它还从故事标题中设置提交消息。

[#69609212] Add new Todo

You can get it from here 你可以从这里得到它

A late comment, but maybe still a useful one. 迟到的评论,但可能仍然是有用的。 I wanted the same solution as provided by @Sjoerd, but I'm a mac user ;) 我想要@Sjoerd提供的相同解决方案,但我是一个mac用户;)

The resulting code looks like this; 结果代码如下所示;

story_id=`git symbolic-ref --short -q HEAD | grep -o "^[[:digit:]]*"`
if [ ! -z "$story_id" -a "$story_id" != " " ]
then
  echo "[#$story_id] $(cat $1)" > "$1"
fi

Note that we prepend the issue ID to the branch name, but it's pretty basic to modify the regex to match the end of the string, not the beginning. 请注意,我们将问题ID添加到分支名称,但是修改正则表达式以匹配字符串的结尾非常基本,而不是开头。 We also add the issue ID to the start of the comment, as this gives a more clear overview in the git log. 我们还将问题ID添加到注释的开头,因为这在git日志中提供了更清晰的概述。 If the above script is ues, each commit message will be prepended with [#<issue ID>] , except when the branch name does not start with an actual issue ID. 如果上述脚本是ues,则每个提交消息将以[#<issue ID>]为前缀,除非分支名称不以实际问题ID开头。

It should be noted that it probably is best if this code is added before any other code in the prepare-commit-msg hook, as this will result in all commits to be prepended, even automatic merges and the like. 应该注意的是,如果在prepare-commit-msg钩子中的任何其他代码之前添加此代码可能是最好的,因为这将导致所有提交被预先添加,甚至自动合并等。

Hope this helps! 希望这可以帮助!

Here is a gem that does exactly what you want: 这是一个完全符合你想要的宝石:

http://github.com/bogdan/git-storyid http://github.com/bogdan/git-storyid

It allows to select a story from a nicely formed menu: 它允许从一个精美的菜单中选择一个故事:

[1] Removing Billing Page
[2] Welcome Email
[3] Tag campaign insertion points and campaigns with an identifier

Indexes(csv): 3
[campaign-tags 3020407]  [#44116647] Initial implementation of campaign tags
 1 file changed, 101 insertion(+), 2 deletions(-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM