问题描述
如何确保来自github PR squash合并的提交注释包含必需的文本?
How can I ensure commit comments from a github PR squash merge contains required text?
我们使用Jira + Github,如果用户在提交注释中输入了Jira问题ID,则这些提交将链接到Jira问题.
We use Jira + Github and if a use enters Jira issue IDs in commit comments those a commits become linked to the Jira issues.
当用户从其私有功能分支合并PR时,他们通常会挤压并合并,这意味着用户可以手动汇总从该分支到较大的集成分支或主节点的单次提交的意图.
When users merge a PR from their private feature branch, they usually squash and merge which means the user can manually summarize the intent of the single commit from that branch to a larger integration branch or master.
如果用户在合并PR时忘记输入它们,那么编辑提交并将文本添加到消息中将变得很痛苦.
If a user forgets to enter them when they merge the PR, it becomes painful to edit the commit and add the text to the message.
是否可以在PR上使用状态检查或提交消息格式化程序,以确保必须有看起来像Jira ID的内容? (AAA-111)
Is there a status check or commit message formatter that I can use on the PR to ensure there must be something that looks like a Jira ID? (AAA-111)
推荐答案
解决此问题的另一种方法*是确保提交消息包含分支名称,在JIRA中,分支名称很可能来自问题标题.
The other approach* around this is to ensure that commit messages include the branch name, which in JIRA are most likely derived from the issue title.
要实现此目的,同事必须在其.git/hooks
目录中包含一个名为commit-msg
的文件,其内容如下:
To achieve this, coworkers have to include in their .git/hooks
directory a file named commit-msg
with the following contents :
#!/bin/bash
current_branch="$(git rev-parse --abbrev-ref HEAD)"
tmp=$(mktemp) || exit
echo "$current_branch $(cat "$1")" > "$tmp"
mv "$tmp" "$1"
然后,当某人在功能分支ABC-1234-customers-cant-log-in
上提交时,将执行如下提交命令:
Then when someone is committing on the feature branch ABC-1234-customers-cant-log-in
, a commit command like this :
git commit -m "Awesome changes"
...实际上将产生以下提交消息:
...will actually produce the following commit message :
ABC-1234-customers-cant-log-in Awesome changes
...,然后JIRA将自动检测到它并将提交链接到问题,从而确保在JIRA问题页面上可靠地总结提交.
...and JIRA will then automatically detect it and link the commit to the issue, thus ensuring a reliable recap of commits on the JIRA issue page.
我们已经在团队中实施了这项政策,它具有以下优势:
We've put this policy in place in my team and it has several advantages :
- 不再忘记提交消息中的JIRA问题编号
- 获得时间
- 在需要时解析提交消息稍微容易一点
(作为附带说明,以防万一,也可以使用git commit -n
根据需要停用此自动行为)
(As a sidenote, just in case, this automated beahviour can also be disactivated on demand, with git commit -n
)
* (请注意,这两种解决方案并不互斥.实际上,您很可能都希望同时使用 Adil's 来实现远程回购的完整性,而这一点则是为了提高本地使用效率)
* (note that these two solutions are not mutually exclusive. In fact, you could very well want both, Adil's for remote repo integrity, and this one for local use efficiency)
这篇关于确保github PR壁球合并提交注释包含问题ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!