Debian Codegraph @

dev/tools/backport-pr.sh

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #!/usr/bin/bashscip-shell filesystem . . `/usr/bin/bash`.
2
3 set -e
4
5 if [[ $# == 0 ]]; then
6 echoscip-shell system . . echo. "Usage: $0 [--no-conflict] [--no-signature-check] [--stop-before-merging] prnum"
7 exit 1
8 fi
9
10 while [[ $# -gt 0 ]]; do
11 case "$1" in
12 --no-conflict)
13 NO_CONFLICTS="true"
14 shift
15 ;;
16 --no-signature-check)
17 NO_SIGNATURE_CHECK="true"
18 shift
19 ;;
20 --stop-before-merging)
21 STOP_BEFORE_MERGING="true"
22 shift
23 ;;
24 *)
25 if [[ "$PRNUM" != "" ]]; then
26 echoscip-shell system . . echo. "PRNUM was already set to $PRNUM and is now being overridden with $1."
27 fi
28 PRNUM="$1"
29 shift
30 esac
31 done
32
33 REMOTE=$(gitscip-shell system . . git. config --get "branch.master.remote" || truescip-shell system . . true.)
34 if [scip-shell system . . `[`. -z "$REMOTE" ]; then
35 echoscip-shell system . . echo. "Branch master has no remote. Using the local state of the master branch instead."
36 MASTER=master
37 else
38 MASTER="$REMOTE/master"
39 fi
40
41 if ! gitscip-shell system . . git. log $MASTER --grep "Merge PR #$PRNUM" | grepscip-shell system . . grep. "." > /dev/nullscip-shell filesystem . . `/dev/null`.; then
42 echoscip-shell system . . echo. "PR #${PRNUM} does not exist."
43 exit 1
44 fi
45
46 SIGNATURE_STATUS=$(gitscip-shell system . . git. log $MASTER --grep "Merge PR #$PRNUM" --format="%G?")
47 gitscip-shell system . . git. log $MASTER --grep "Merge PR #$PRNUM" --format="%GG"
48 if [[ "$NO_SIGNATURE_CHECK" != "true" && "$SIGNATURE_STATUS" != "G" ]]; then
49 echoscip-shell system . . echo.
50 read -p "Merge commit does not have a good (valid) signature. Bypass? [y/N] " -n 1 -r
51 echoscip-shell system . . echo.
52 if [[ ! $REPLY =~ ^[Yy]$ ]]; then
53 exit 1
54 fi
55 fi
56
57 BRANCH=backport-pr-${PRNUM}
58 RANGE=$(gitscip-shell system . . git. log $MASTER --grep "Merge PR #$PRNUM" --format="%P" | sedscip-shell system . . sed. 's/ /../')
59 MESSAGE=$(gitscip-shell system . . git. log $MASTER --grep "Merge PR #$PRNUM" --format="%s" | sedscip-shell system . . sed. 's/Merge/Backport/')
60
61 if [[ "$(git rev-parse --abbrev-ref HEAD)" == "$BRANCH" ]]; then
62
63 if ! gitscip-shell system . . git. cherry-pick --continue; then
64 echoscip-shell system . . echo. "Please fix the conflicts, then relaunch the script."
65 exit 1
66 fi
67 gitscip-shell system . . git. checkout -
68
69 elif gitscip-shell system . . git. checkout -b "$BRANCH"; then
70
71 if ! gitscip-shell system . . git. cherry-pick -x "${RANGE}"; then
72 if [[ "$NO_CONFLICTS" == "true" ]]; then
73 gitscip-shell system . . git. status
74 echoscip-shell system . . echo. "Conflicts! Aborting..."
75 gitscip-shell system . . git. cherry-pick --abort
76 gitscip-shell system . . git. checkout -
77 gitscip-shell system . . git. branch -d "$BRANCH"
78 exit 1
79 fi
80 echoscip-shell system . . echo. "Please fix the conflicts, then relaunch the script."
81 exit 1
82 fi
83 gitscip-shell system . . git. checkout -
84
85 else
86
87 echoscip-shell system . . echo.
88 read -p "Skip directly to merging phase? [y/N] " -n 1 -r
89 echoscip-shell system . . echo.
90 if [[ ! $REPLY =~ ^[Yy]$ ]]; then
91 exit 1
92 fi
93
94 fi
95
96 if ! gitscip-shell system . . git. diff --exit-code HEAD "${BRANCH}" -- "*.mli"; then
97 echoscip-shell system . . echo.
98 read -p "Some mli files are modified. Bypass? [y/N] " -n 1 -r
99 echoscip-shell system . . echo.
100 if [[ ! $REPLY =~ ^[Yy]$ ]]; then
101 exit 1
102 fi
103 fi
104
105 if [[ "$STOP_BEFORE_MERGING" == "true" ]]; then
106 exit 0
107 fi
108
109 gitscip-shell system . . git. merge -S --no-ff "${BRANCH}" -m "${MESSAGE}"
110 gitscip-shell system . . git. branch -d "${BRANCH}"
111
112 # To-Do:
113 # - Support for backporting a PR before it is merged
114 # - Automatically backport all PRs in the "Waiting to be backported" column using a command like:
115 # $ curl -s -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.inertia-preview+json" https://api.github.com/projects/columns/1358120/cards | jq -r '.[].content_url' | grep issue | sed 's/^.*issues\/\([0-9]*\)$/\1/' | tac
116 # (The ID of the column must first be obtained through https://api.github.com/repos/coq/coq/projects then https://api.github.com/projects/819866/columns.)
117 # - Then move each of the backported PR to the subsequent columns automatically as well...