From 5dbf329cd9fa53f1800d355354604ec4aef8e571 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 5 Jul 2024 23:15:41 +0200 Subject: [PATCH] GH-704 - Add script to back-port commits. The script creates tickets for the back-ports, cherry-picks the latest commit of the current branch and adapts the commit messages of them to the ticket ids of the newly created tickets. --- etc/create-backport-tickets.sh | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 etc/create-backport-tickets.sh diff --git a/etc/create-backport-tickets.sh b/etc/create-backport-tickets.sh new file mode 100755 index 00000000..c703437c --- /dev/null +++ b/etc/create-backport-tickets.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Format $ticketNumer $targetVersion[] + +sourceGh="GH-$1" +branch=$(git branch --show-current) +json=$(gh issue view $1 --json=title,labels) + +title=$(echo $json | jq -r '.title') +labels=$(echo $json | jq -r '.labels[].name' | paste -sd ',' -) + +number=$1 + +# For each of the target versions +for version in ${@:2} +do + number=$(gh issue create --title "$title" --body "Back-port of $sourceGh." --label "$labels" --assignee "@me" --milestone "$version" | awk -F '/' '{print $NF}') + + # Turn 1.5.6 into 1.5.x + targetBranch="$(echo "$version" | grep -oE '^[0-9]+\.[0-9]+').x" + + # Checkout target branch and cherry-pick commit + + echo "Checking out branch $targetBranch" + git checkout $targetBranch + + echo "Cherry-pick commit from $branch" + git cherry-pick $branch + + # Replace ticket reference with new one + targetGh="GH-$number" + expression="s/$sourceGh/$targetGh/g" + message=$(git log -1 --pretty=format:"%s" | sed $expression) + + # Update commit message to refer to new ticket + echo "Adapt commit message from $sourceGh to $targetGh" + git commit --amend -m "$message" +done + +# Return to original branch +git checkout $branch