Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit 434e25c

Browse files
fanf2oerdnj
authored andcommitted
Auto-tag merge requests created by git-replay-merge
The target branch is added to the title of the MR, and a "Backport" label is added. If the target branch starts with "v" a version label is added too. While I am here, clean up remnants of the old gitlab API (which has been replaced by push options for our purposes) and improve the command-line parsing.
1 parent 2037b1d commit 434e25c

File tree

1 file changed

+50
-30
lines changed

1 file changed

+50
-30
lines changed

util/git-replay-merge.sh

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@ SELF="$(basename $0)"
1717
SELF="${SELF/-/ }"
1818

1919
STATE_FILE=".git/REPLAY_MERGE"
20+
DONT_TAG=${DONT_TAG:=false}
2021
DONT_PUSH=${DONT_PUSH:=false}
2122
DONT_ACCEPT=${DONT_ACCEPT:=false}
2223

23-
GITLAB_API_ENDPOINT=${GITLAB_API_ENDPOINT:=https://gitlab.isc.org/api/v4}
24-
GITLAB_URI=${GITLAB_URI:=$(echo $GITLAB_API_ENDPOINT | cut -f 1-3 -d /)}
25-
GITLAB_PROJECT_ID=${GITLAB_PROJECT_ID:=1}
26-
GITLAB_PROJECT_GROUP=${GITLAB_PROJECT_GROUP:=isc-projects}
27-
GITLAB_PROJECT_NAME=${GITLAB_PROJECT_NAME:=bind9}
28-
2924
die() {
3025
for MESSAGE in "$@"; do
3126
echo -e "${MESSAGE}" >&2
@@ -36,17 +31,14 @@ die() {
3631
die_with_usage() {
3732
die "Usage:" \
3833
"" \
39-
" ${SELF} <merge_commit_id> <target_remote> <target_branch>" \
40-
" ${SELF} --no-push" \
41-
" ${SELF} --continue" \
42-
" ${SELF} --abort"
43-
}
44-
45-
verify_gitlab_cli() {
46-
which gitlab >/dev/null 2>&1 || \
47-
die "You need to have gitlab cli installed and configured: "\
48-
"" \
49-
"$ gem install --user-install gitlab"
34+
"${SELF} [options] <merge_commit_id> <target_remote> <target_branch>" \
35+
"${SELF} --continue" \
36+
"${SELF} --abort" \
37+
"" \
38+
"options:" \
39+
" --no-push" \
40+
" --no-tag" \
41+
""
5042
}
5143

5244
die_with_continue_instructions() {
@@ -173,21 +165,39 @@ resume() {
173165
fi
174166
fi
175167

176-
if [[ "$DONT_PUSH" = "true" ]]; then
168+
if $DONT_PUSH; then
177169
die_before_push
178170
fi
179171

180-
if [[ "$DONT_ACCEPT" = "true" ]]; then
181-
AUTOMERGE=""
172+
if $DONT_ACCEPT; then
173+
AUTO_MERGE=""
182174
else
183-
AUTO_MERGE="-o merge_request.merge_when_pipeline_succeeds"
175+
AUTO_MERGE="merge_request.merge_when_pipeline_succeeds"
176+
fi
177+
178+
TITLE=""
179+
LABEL_VERSION=""
180+
LABEL_BACKPORT=""
181+
182+
if ! $DONT_TAG && [[ $TARGET_BRANCH == v9_[0-9][0-9] ]]; then
183+
184+
version="9.${TARGET_BRANCH#v9_}"
185+
186+
TITLE="$(git show --format=%b ${SOURCE_COMMIT} | head -n 1)"
187+
TITLE="merge_request.title=[${version}] ${TITLE}"
188+
189+
LABEL_VERSION="merge_request.label=v${version}"
190+
LABEL_BACKPORT="merge_request.label=Backport"
184191
fi
185192

186193
git push -u ${TARGET_REMOTE} \
187194
-o merge_request.create \
188195
-o merge_request.remove_source_branch \
189196
-o "merge_request.target=${TARGET_BRANCH}" \
190-
${AUTO_MERGE} \
197+
${AUTO_MERGE:+-o} "${AUTO_MERGE}" \
198+
${TITLE:+-o} "${TITLE}" \
199+
${LABEL_VERSION:+-o} "${LABEL_VERSION}" \
200+
${LABEL_BACKPORT:+-o} "${LABEL_BACKPORT}" \
191201
"${REPLAY_BRANCH}:${REPLAY_BRANCH}"
192202

193203
cleanup
@@ -208,6 +218,7 @@ cleanup() {
208218
cd $(git rev-parse --show-toplevel)
209219

210220
next_action="go"
221+
args=3
211222
while [[ $# -ge 1 ]]; do
212223
case "$1" in
213224
"--no-push")
@@ -216,29 +227,38 @@ while [[ $# -ge 1 ]]; do
216227
"--push")
217228
DONT_PUSH=false
218229
;;
230+
"--no-tag")
231+
DONT_TAG=true
232+
;;
233+
"--tag")
234+
DONT_TAG=false
235+
;;
219236
"--abort")
220237
die_if_not_in_progress
221238
source "${STATE_FILE}"
222239
next_action="cleanup"
240+
args=0
241+
shift
242+
break
223243
;;
224244
"--continue")
225-
verify_gitlab_cli
226245
die_if_not_in_progress
227246
source "${STATE_FILE}"
228247
next_action="resume"
229-
;;
230-
*)
231-
if [[ $# -ne 3 ]]; then
232-
die_with_usage
233-
fi
248+
args=0
249+
shift
234250
break
235251
;;
252+
--*) die_with_usage
253+
;;
254+
*) break
255+
;;
236256
esac
237257
shift
238258
done
239259

240-
if [[ "DONT_PUSH" = "false" ]]; then
241-
verify_gitlab_cli
260+
if [[ $# -ne $args ]]; then
261+
die_with_usage
242262
fi
243263

244264
$next_action "$@"

0 commit comments

Comments
 (0)