Ensure github PR squash merge commit comments contain issue ID

前端 未结 2 1952
一个人的身影
一个人的身影 2020-12-21 06:09

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 t

2条回答
  •  天命终不由人
    2020-12-21 06:46

    If you're using GitHub Enterprise, you can set up a pre-receive hook to reject commits that don't have a JIRA ticket number in them.

    Check out the example here:

    #!/bin/bash
    #
    # check commit messages for JIRA issue numbers formatted as [JIRA-]
    
    REGEX="\[JIRA\-[0-9]*\]"
    
    ERROR_MSG="[POLICY] The commit doesn't reference a JIRA issue"
    
    while read OLDREV NEWREV REFNAME ; do
      for COMMIT in `git rev-list $OLDREV..$NEWREV`;
      do
        MESSAGE=`git cat-file commit $COMMIT | sed '1,/^$/d'`
        if ! echo $MESSAGE | grep -iqE "$REGEX"; then
          echo "$ERROR_MSG: $MESSAGE" >&2
          exit 1
        fi
      done
    done
    exit 0
    

提交回复
热议问题