github-merge-pr: add Link: tag and Committer SoB
authorChristian Marangi <ansuelsmth@gmail.com>
Sat, 27 Apr 2024 11:31:33 +0000 (13:31 +0200)
committerChristian Marangi <ansuelsmth@gmail.com>
Sat, 27 Apr 2024 11:31:33 +0000 (13:31 +0200)
If we can rebase the Pull Request, append the Link: tag and Committer SoB
tag to the end of the commit message to better reference the source of
the commit and who Approved/Committed.

In theory any modification to the commit should always have a SoB hence
a committer rebasing the Pull Request should add the SoB tag.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
github-merge-pr.sh

index 7f23435a7c1e9885a54e3f38bdb45c2b74a425dc..d63b3455cad93c3db18c05debe504e2900159ae2 100755 (executable)
@@ -120,6 +120,28 @@ if [ "$(echo "$PR_INFO" | jq -r ".maintainer_can_modify")" == "true" ]; then
                exit 9
        fi
 
+       # Add to each commit Link: https://github.com/openwrt/openwrt/pull/$PRID
+       if ! $GIT filter-repo --message-callback "
+               return message + b\"Link: https://github.com/openwrt/openwrt/pull/$PRID\"
+       " --refs $BRANCH..$LOCAL_PR_BRANCH; then
+               echo "Failed to add Link: Pull Request tag" >&2
+               exit 9
+       fi
+
+       # Remove any previous SoB tag if the Pull Request Author and Committer match
+       if ! $GIT filter-repo --message-callback "
+               return message.replace(b\"Signed-off-by: $(git config user.name) <$(git config user.email)>\",b\"\")
+       " --refs $BRANCH..$LOCAL_PR_BRANCH; then
+               echo "Failed to remove previous Committer SoB tag" >&2
+               exit 9
+       fi
+
+       # Add Committer SoB to better reference who merged the thing last
+       if ! $GIT rebase origin/$BRANCH $LOCAL_PR_BRANCH --exec "git commit -s --amend -C HEAD"; then
+               echo "Failed to add Committer SoB tag" >&2
+               exit 9
+       fi
+
        echo "Force pushing $LOCAL_PR_BRANCH to HEAD:$PR_BRANCH for $PR_USER"
        if ! $GIT push $PR_USER HEAD:$PR_BRANCH --force; then
                echo "Failed to force push HEAD to $PR_USER" >&2