Skip to content

Commit 5dbf329

Browse files
committed
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.
1 parent e7515cc commit 5dbf329

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

etc/create-backport-tickets.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Format $ticketNumer $targetVersion[]
3+
4+
sourceGh="GH-$1"
5+
branch=$(git branch --show-current)
6+
json=$(gh issue view $1 --json=title,labels)
7+
8+
title=$(echo $json | jq -r '.title')
9+
labels=$(echo $json | jq -r '.labels[].name' | paste -sd ',' -)
10+
11+
number=$1
12+
13+
# For each of the target versions
14+
for version in ${@:2}
15+
do
16+
number=$(gh issue create --title "$title" --body "Back-port of $sourceGh." --label "$labels" --assignee "@me" --milestone "$version" | awk -F '/' '{print $NF}')
17+
18+
# Turn 1.5.6 into 1.5.x
19+
targetBranch="$(echo "$version" | grep -oE '^[0-9]+\.[0-9]+').x"
20+
21+
# Checkout target branch and cherry-pick commit
22+
23+
echo "Checking out branch $targetBranch"
24+
git checkout $targetBranch
25+
26+
echo "Cherry-pick commit from $branch"
27+
git cherry-pick $branch
28+
29+
# Replace ticket reference with new one
30+
targetGh="GH-$number"
31+
expression="s/$sourceGh/$targetGh/g"
32+
message=$(git log -1 --pretty=format:"%s" | sed $expression)
33+
34+
# Update commit message to refer to new ticket
35+
echo "Adapt commit message from $sourceGh to $targetGh"
36+
git commit --amend -m "$message"
37+
done
38+
39+
# Return to original branch
40+
git checkout $branch

0 commit comments

Comments
 (0)