Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

git - Ensure github PR squash merge commit comments contain issue ID

How can I ensure commit comments from a github PR squash merge contains required text?

We use Jira + Github and if a use enters Jira issue IDs in commit comments those a commits become linked to the Jira issues.

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.

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.

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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"

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

...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 :

  • no more forgetting JIRA issue numbers in commit messages
  • gain of time
  • slightly easier to parse commit messages when you need it

(As a sidenote, just in case, this automated beahviour can also be disactivated on demand, with git commit -n)

* (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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...