File: cherry-picker.sh

package info (click to toggle)
golang-mongodb-mongo-driver 1.17.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 25,988 kB
  • sloc: perl: 533; ansic: 491; python: 432; sh: 327; makefile: 174
file content (78 lines) | stat: -rwxr-xr-x 1,951 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -e

sha=$1
target=${2:-master}
dirname=$(mktemp -d)
user=$(git config github.user)

if [ -z "$user" ]; then
    echo "Please set GitHub User"
    echo "git config --global github.user <github_handle>"
    exit 1
fi

mkdir -p $dirname
if [ -z "$AUTH_TOKEN" ]; then
    git clone git@github.com:mongodb/mongo-go-driver.git $dirname
else
    echo "$AUTH_TOKEN" > mytoken.txt
    gh auth login --with-token < mytoken.txt
    git clone https://github.com/mongodb/mongo-go-driver.git $dirname
fi

cd $dirname
if [ -z "$AUTH_TOKEN" ]; then
    git remote add $user git@github.com:$user/mongo-go-driver.git
else
    git remote add $user https://$user:${AUTH_TOKEN}@github.com/$user/mongo-go-driver.git
fi

gh repo set-default mongodb/mongo-go-driver
branch="cherry-pick-$sha"
head="$user:$branch"
git fetch origin
git checkout -b $branch origin/$target
git cherry-pick -x $sha || true

files=$(git ls-files -m)
if [ -n "${files}" ]; then
    EDITOR=${EDITOR:-$(git config core.editor)}
    EDITOR=${EDITOR:-vim}
    for fname in $files; do
        echo "Fixing $fname..."
        $EDITOR $fname
        git add $fname
    done
    echo "Finishing cherry pick."
    git cherry-pick --continue
fi

old_title=$(git --no-pager log  -1 --pretty=%B | head -n 1)
ticket=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+).*/\1/')
text=$(echo $old_title | sed -r 's/([A-Z]+-[0-9]+) (.*) \(#[0-9]*\)/\2/')
pr_number=$(echo $old_title| sed -r 's/.*(#[0-9]*)\)/\1/')

title="$ticket [$target] $text"
body="Cherry-pick of $pr_number to $target"

echo
echo "Creating PR..."
echo "Title: $title"
echo "Body: $body"
echo "Base: $target"
echo "Head: $head"
echo

if [ -n "$GITHUB_ACTOR" ]; then
    choice=Y
else
    read -p 'Push changes? (Y/n) ' choice
fi

if [[ "$choice" == "Y" || "$choice" == "y" || -z "$choice" ]]; then
    if [ -n "$user" ]; then
        git push $user
    fi
    gh pr create --title "$title" --base $target --head $head --body "$body"
fi