-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb-pr
executable file
·584 lines (503 loc) · 18.9 KB
/
bb-pr
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
#!/usr/bin/env bash
# Requires you to have exported 2 environment variables:
# export BITBUCKET_USER=my_bitbucket_username
# export BITBUCKET_TOKEN=my_bitbucket_app_password
#
# c.f. https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/
# Requires:
# - jq : https://github.com/jqlang/jq
# - jf : https://github.com/sayanarijit/jf (to json encode multiline comments)
# - curl : why of course it does!, why haven't you got it?
set -eo pipefail
declare -A emojiMap
# build status
emojiMap[SUCCESSFUL]="✅"
emojiMap[FAILED]="⛔"
emojiMap[INPROGRESS]="⌚"
emojiMap[STOPPED]="❌"
# participant.state (approval)
emojiMap[approved]="👍"
emojiMap[changes_requested]="✒️"
emojiMap[null]="👀"
# participant.approved (true|false)
emojiMap[true]="👍"
emojiMap[false]="👀"
_giturl_to_base() {
local url=$1
url=${url%%.git}
url=${url#*bitbucket*:}
url=${url#*bitbucket*/}
echo "$url"
}
EMOJIS_DISABLED=${BB_PR_DISABLE_EMOJIS:-false}
BITBUCKET_API_BASE="https://api.bitbucket.org/2.0"
BITBUCKET_REPO_API_URL="$BITBUCKET_API_BASE/repositories"
GIT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || true
GIT_REMOTE=$(_giturl_to_base "$(git remote get-url origin 2>/dev/null)") || true
BITBUCKET_SLUG=${GIT_REMOTE%.git}
GIT_REMOTE_BRANCH_FULL=$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null) || true
GIT_REMOTE_BRANCH=${GIT_REMOTE_BRANCH_FULL#*/}
GIT_LOCAL_WORKING_BRANCH=$(git branch --show-current 2>/dev/null) || true
GIT_REMOTE_DEFAULT=$(git remote show origin 2>/dev/null | grep 'HEAD branch' | cut -d' ' -f5) || true
ACTION_LIST="help|list|checkout|co|squash-msg|squash-merge|approve|unapprove|decline|close-branch|completion|status|whoami|ready"
WORK_FILE=$(mktemp --tmpdir bb-pr-squash-merge.XXXXXX)
SQUASH_MERGE_OUTPUT=$(mktemp --tmpdir bb-pr-squash-merge.XXXXXX)
CURL_AUTH="${BITBUCKET_USER}:${BITBUCKET_TOKEN}"
CURL_HEADER_CTYPE="Content-Type: application/json"
CURL_HEADER_ACCEPT="Accept: application/json"
CURL_FLAGS="-fsSL"
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
trap cleanup 1 2 15
emoji() {
local key=$1
if [[ "$EMOJIS_DISABLED" == "false" ]]; then
for mapEntry in "${!emojiMap[@]}"
do
[[ "$key" == "$mapEntry" ]] && echo "${emojiMap[${key}]}" && return
done
fi
echo "$key"
}
# Need to get someone to let me test on a mac.
# Macs can use pbcopy apparently, but they should just
# set the BB_PR_CLIPBOARD env variable
clipboard_exe() {
if [[ -z "$BB_PR_CLIPBOARD" ]]; then
if [[ -n "$WSL_DISTRO_NAME" ]]; then
LOCAL_DRIVE_C=$(mount | grep "9p" | grep "path=C:" | awk '{print $3}')
echo "$LOCAL_DRIVE_C/windows/system32/clip.exe"
elif [[ -n "${XDG_CURRENT_DESKTOP}" ]]; then
echo "xclip"
fi
else
echo "$BB_PR_CLIPBOARD"
fi
}
cleanup() {
if [[ -n "${WORK_FILE:-}" ]]; then
rm -f "$WORK_FILE"
fi
if [[ -n "${SQUASH_MERGE_OUTPUT:-}" ]]; then
rm -f "$SQUASH_MERGE_OUTPUT"
fi
}
get_pr_number() {
local pr_number="$1"
if [[ -z "$pr_number" && -n "${GIT_REMOTE_BRANCH}" ]]; then
query=$(printf "source.branch.name=\"%s\" AND state=\"OPEN\"" "${GIT_REMOTE_BRANCH}")
query_uri=$(printf %s "${query}" | jq -sRr @uri)
local pull_request_query_url="${BITBUCKET_REPO_API_URL}/${BITBUCKET_SLUG}/pullrequests?q=${query_uri}"
pr_number=$(curl $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "${pull_request_query_url}" | jq .values[0].id)
if [ "$pr_number" != "null" ]; then
echo "$pr_number"
fi
else
echo "$pr_number"
fi
}
action_help() {
cat <<EOF
Tool that helps management of bitbucket pull requests from the commandline
Usage: $(basename "$0") [$ACTION_LIST] [options]
help : show this help
list : list (open) PRs in this repo
checkout : check out a pull request in git
co : alias for checkout
squash-msg : copy a reasonable message to the clipboard for merging a PR
squash-merge : merge the PR using the message from 'squash-msg'
approve : approve a PR (though should you from the CLI?)
unapprove : remove your approval
decline : decline a PR
close-branch : change the 'close_source_branch' field
completion : returns command bash completion
status : shows the overall status of the requested PR
whoami : shows some information about your current user
- requires 'account read' scope
ready : mark a PR as ready for review, which means that
.bitbucket/bitbucket-pr.yml is parsed and the
uuids are added as reviewers.
- The PR author will be removed from the potential
list of reviewers.
'squash-msg' | 'squash-merge' | 'approve' | 'unapprove' | 'decline'
'close-branch' | 'status' | 'ready'
Without an argument, the pull request that belongs to the current branch is used.
Arguments
<PR> The PR number to operate on.
'close-branch' can toggle true or false (default true)
-c : true|false (e.g. -c false) to toggle the state
'squash-merge' can do dangerous things
-D : force close the branch regardless of the PR setting. If not
specified then the PR will be merged according to the PR
settings.
'list' can additionally filter by state
-s : the state (e.g. -s OPEN) OPEN|MERGED|DECLINED|SUPERSEDED
If you get it wrong, you'll get all the PRs which may take
longer than you want. Defaults to 'OPEN'
Examples
If we are on the branch 'fix/owasp'
# Squash Merge the PR associated with 'fix/owasp' and close (delete) the source branch
# The local branch 'fix/owasp' is deleted and you will end up on the 'main' branch
bsh ❯ bb-pr squash-merge -D
# Squash Merge the PR associated with 'feat/owasp' according its PR settings
# The local branch 'fix/owasp' is deleted and you will end up on the 'main' branch
bsh ❯ bb-pr squash-merge
# Squash Merge the PR#5 leaving you on the 'feat/owasp'
bsh ❯ bb-pr squash-merge 5
# Squash Merge the PR#5 deleting the source branch leaving you on the 'feat/owasp'
bsh ❯ bb-pr squash-merge -D 5
EOF
exit 2
}
action_list() {
local jq_transform='.values[]
| { "id": (.id | tostring), "title": .title, "url": .links.html.href }
| "\(.id)|\(.title)|\(.url)"
'
local response
local next
local state="OPEN"
while getopts 's:' flag; do
case "${flag}" in
s) state="${OPTARG}" ;;
*) action_help ;;
esac
done
state=$(echo "$state" | tr '[:lower:]' '[:upper:]')
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests?state=$state"
{
next="$pull_request_url"
until [ "$next" == "null" ]; do
response=$(curl $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$next")
echo "$response" | jq --raw-output "$jq_transform"
next=$(echo "$response" | jq --raw-output ".next")
done
} | sort | column -s "|" -t -N "ID,TITLE,URL"
}
action_decline() {
local pr_number="$1"
pr_number=$(get_pr_number "$pr_number")
if [[ -z "$pr_number" ]]; then
echo ">>> No PR"
exit 1
fi
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number/decline"
curl -X POST $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$pull_request_url" | jq --raw-output '"\(.state)"'
}
action_approve() {
local pr_number="$1"
pr_number=$(get_pr_number "$pr_number")
if [[ -z "$pr_number" ]]; then
echo ">>> No PR"
exit 1
fi
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number/approve"
curl -X POST $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$pull_request_url" | jq --raw-output '"\(.state)"'
}
action_unapprove() {
local pr_number="$1"
pr_number=$(get_pr_number "$pr_number")
if [[ -z "$pr_number" ]]; then
echo ">>> No PR"
exit 1
fi
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number/approve"
curl -X DELETE $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$pull_request_url"
}
action_squash-msg() {
local pr_number=$1
local squash_merge_msg
pr_number=$(get_pr_number "$pr_number")
if [[ -z "$pr_number" ]]; then
echo ">>> No PR"
exit 1
fi
squash_merge_msg=$(emit_squash_merge_msg "$pr_number")
echo "---"
echo "$squash_merge_msg"
echo "---"
echo "is now in your clipboard"
# shellcheck disable=SC2091
echo "$squash_merge_msg" | eval "$(clipboard_exe)"
}
action_squash-merge() {
local squash_merge_msg
local json_payload
local jq_transform='"\(.id)|\(.state)"'
#shellcheck disable=SC2016
local failure_jq_transform='.error | .message as $message | .fields | to_entries[] | "\($message)|\(.value)"'
local delete_local_branch=""
local force_close_branch=""
ARGS=$(getopt --options 'D' -- "${@}")
eval "set -- ${ARGS}"
while true; do
case "${1}" in
-D)
force_close_branch="true"
shift
;;
--)
shift
break
;;
*) action_help ;;
esac
done
local pr_number="$1"
# If there's no PR number then we assume we're branch based
# and since we are squash merging we try to behave like gh squash-merge
# and delete the local working branch
if [[ -z "$pr_number" ]]; then
pr_number=$(get_pr_number "")
delete_local_branch="true"
fi
if [[ -z "$pr_number" ]]; then
echo ">>> No PR"
exit 1
fi
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number/merge"
squash_merge_msg=$(emit_squash_merge_msg "$pr_number")
# https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/
# mentions a mandatory 'type' in the request body, but there's no docs
# as to what the value should be; but we should be safe to
# assume it's the 'type' that you get back when you grab the pullrequest
# /repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}
# probably want some tempfile action for a bit of --data @filename
if [[ -n "$force_close_branch" ]]; then
json_payload=$(jf '{%**q}' "type" "pullrequest" "message" "$squash_merge_msg" "close_source_branch" "true" "merge_strategy" "squash")
else
json_payload=$(jf '{%**q}' "type" "pullrequest" "message" "$squash_merge_msg" "merge_strategy" "squash")
fi
echo "$json_payload" >"$WORK_FILE"
http_code=$(curl -X POST -sSL --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" -H "$CURL_HEADER_CTYPE" "$pull_request_url" "--data" "@$WORK_FILE" -o "$SQUASH_MERGE_OUTPUT" -w "%{http_code}")
if [[ "$http_code" -ge "400" ]]; then
#shellcheck disable=SC2002
errorMsg=$(cat "${SQUASH_MERGE_OUTPUT}" | jq --raw-output "$failure_jq_transform" | column -s "|" -t -N "ID,STATE")
if [[ "$errorMsg" != "" ]]; then
echo -e "$errorMsg"
else
cat "${SQUASH_MERGE_OUTPUT}"
fi
echo Operation failed...
exit 1
else
#shellcheck disable=SC2002
cat "${SQUASH_MERGE_OUTPUT}" | jq --raw-output "$jq_transform" | column -s "|" -t -N "ID,STATE"
if [[ -n "$delete_local_branch" ]]; then
git_switch_default
fi
fi
}
action_close-branch() {
close_branch="true"
ARGS=$(getopt --options 'c:' -- "${@}")
eval "set -- ${ARGS}"
while true; do
case "${1}" in
-c)
close_branch="${2}"
shift 2
;;
--)
shift
break
;;
*) action_help ;;
esac
done
local pr_number="$1"
pr_number=$(get_pr_number "$pr_number")
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number"
json_payload=$(jf '{%**q}' "close_source_branch" "$close_branch")
echo "$json_payload" >"$WORK_FILE"
curl -X PUT $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" -H "$CURL_HEADER_CTYPE" "$pull_request_url" "--data" "@$WORK_FILE" | jq --raw-output '"close_source_branch now \(.close_source_branch)"'
}
action_checkout() {
local pr_number="$1"
if [[ -z "$pr_number" ]]; then
echo ">>> No PR"
exit 1
fi
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number"
body=$(curl $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$pull_request_url")
branch=$(echo "$body" | jq --raw-output ".source.branch.name")
git fetch --all
git switch "$branch"
}
action_co() {
action_checkout "$@"
}
action_completion() {
cat "${SCRIPT_DIR}/completion.sh"
}
# If we wanted to replicate the merge checks view in the UI we would
# have to manually do https://jira.atlassian.com/browse/BCLOUD-22014
# build-status we are doing
action_status() {
local pr_number=$1
local name
local status
local statusUrl
local approvalList
local buildStatusList
pr_number=$(get_pr_number "$pr_number")
if [[ -z "$pr_number" ]]; then
echo ">>> No PR"
exit 1
fi
__status_header "$pr_number"
__status_builds "$pr_number"
__status_approvals "$pr_number"
echo -e ">>> PR commit message:\n"
emit_squash_merge_msg "$pr_number"
}
action_whoami() {
curl $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$BITBUCKET_API_BASE/user" | jq 'del (.links)'
}
# Use bb-pr whoami to find your UUID.
#
#shellcheck disable=SC2002
action_ready() {
local pr_number=$1
#shellcheck disable=SC2016
local jq_reviewers='
walk(if type == "object" and has("name") then del(.name) else . end) |
walk (if type == "object" and .uuid == $uuid then empty else . end)'
local reviewers_file
local pr_body
local login_uuid
local http_code
pr_number=$(get_pr_number "$pr_number")
if [[ -z "$pr_number" ]]; then
echo ">>> No PR"
exit 1
fi
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number"
reviewers_file="${BITBUCKET_REVIEWERS:-${GIT_ROOT:-.}/.bitbucket/bitbucket-pr.yml}"
if [[ ! -s "$reviewers_file" ]]; then
echo -e "\n>>> Didn't find $reviewers_file; nothing to do;"
exit 0
fi
login_uuid=$(curl $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$pull_request_url" | jq --raw-output '.author.uuid')
pr_body="$(cat "$reviewers_file" | yq -p yaml -o json | jq -r --arg uuid "$login_uuid" "$jq_reviewers")"
http_code=$(curl -X PUT -sSL --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" -H "$CURL_HEADER_CTYPE" "$pull_request_url" "--data" "$pr_body" -o "$SQUASH_MERGE_OUTPUT" -w "%{http_code}")
if [[ "$http_code" -ge "400" ]]; then
errorMsg=$(cat "$SQUASH_MERGE_OUTPUT" | jq --raw-output '.error.message')
if [[ "$errorMsg" != "" ]]; then
echo -e "$errorMsg"
else
cat "${SQUASH_MERGE_OUTPUT}"
fi
echo Operation failed...
exit 1
else
cat "$SQUASH_MERGE_OUTPUT" | jq --raw-output '"Added reviewer: \(.reviewers | .[] | .display_name)"'
fi
}
__status_header() {
local pr_number=$1
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number"
body=$(curl $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$pull_request_url")
html_url=$(echo "$body" | jq -r '.links.html.href')
echo -e ">>> PR#$pr_number: $html_url\n"
}
__status_approvals() {
local pr_number=$1
local name
local status
local uuid
local approvalList
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number"
approvalList=$(curl -X GET $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$pull_request_url" \
| jq -r -c '.participants[] | select( .role == "REVIEWER") | { "name" : .user.display_name, "uuid": .user.uuid, "approved": .state}')
if [[ -n "$approvalList" ]]; then
while IFS= read -r line; do
name=$(echo "$line" | jq -r '.name')
status=$(emoji "$(echo "$line" | jq -r '.approved')")
uuid=$(echo "$line" | jq -r '.uuid')
echo "$name|$status|$uuid"
done <<<"$approvalList" | column -s"|" -t -N "NAME,APPROVED,UUID"
echo ""
else
echo -e ">>> No REVIEWERS added to this PR\n"
fi
}
__status_builds() {
local pr_number=$1
local name
local status
local statusUrl
local buildStatusList
local build_status_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number/statuses"
buildStatusList=$(curl -X GET $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$build_status_url" \
| jq -r -c '.values[] | { "name" : .name, "state" : .state, "url": .url }')
if [[ -n "$buildStatusList" ]]; then
while IFS= read -r line; do
name=$(echo "$line" | jq -r '.name')
status=$(emoji "$(echo "$line" | jq -r '.state')")
statusUrl=$(echo "$line" | jq -r '.url')
echo "$status|$name|$statusUrl"
done <<<"$buildStatusList" | column -s"|" -t -N "STATUS,JOB,URL"
echo ""
fi
}
git_switch_default() {
if [[ -n "$GIT_REMOTE_DEFAULT" && "$GIT_LOCAL_WORKING_BRANCH" ]]; then
git switch "$GIT_REMOTE_DEFAULT"
git pull
git branch --delete --force --remotes "$GIT_REMOTE_BRANCH_FULL"
git branch --delete --force "$GIT_LOCAL_WORKING_BRANCH"
fi
}
emit_squash_merge_msg() {
local body
local pr_approvers
local squash_merge_details
local title
local description
local pr_number="$1"
local jq_approvers='.participants | .[] | select(.approved==true) | "Approved-By: \(.user.display_name)"'
local pull_request_url="$BITBUCKET_REPO_API_URL/$BITBUCKET_SLUG/pullrequests/$pr_number"
body=$(curl $CURL_FLAGS --user "$CURL_AUTH" -H "$CURL_HEADER_ACCEPT" "$pull_request_url")
description=$(echo "$body" | jq --raw-output '.description | gsub("\\\\"; "")')
title=$(echo "$body" | jq --raw-output ".title")
# Is - is nicer than *
squash_merge_details=$(echo "$description" | awk '/SQUASHMERGESTART/,/SQUASHMERGEEND/' |
{ grep -v "SQUASHMERGE" || test $? = 1; } |
sed -E "s|^\*|-|")
squash_merge_footer=$(echo "$description" | awk '/SQUASHMERGEFOOTERSTART/,/SQUASHMERGEFOOTEREND/' |
{ grep -v "SQUASHMERGEFOOTER" || test $? = 1; } | tr -s '\n' '\n')
pr_approvers=$(echo "$body" | jq --raw-output "$jq_approvers" | tr -s '\n' '\n')
shopt -s extglob
squash_merge_details=${squash_merge_details%%*($'\n')} # remove all trailing newlines
squash_merge_details=${squash_merge_details##*($'\n')} # remove all leading newlines
squash_merge_footer=${squash_merge_footer%%*($'\n')} # remove all trailing newlines
squash_merge_footer=${squash_merge_footer##*($'\n')} # remove all leading newlines
shopt -u extglob
squash_merge_details=$(echo "${squash_merge_details}" | sed -E 's/\[(.*?)\]\(.*?\)/\1/g') # remove markdown links
squash_merge_footer=$(echo "${squash_merge_footer}" | sed -E 's/\[(.*?)\]\(.*?\)/\1/g') # remove markdown links
if [[ -n "$squash_merge_details" ]]; then
squash_merge_details="${squash_merge_details}"$'\n'$'\n' # add linebreaks to space out approver if set
fi
if [[ -n "$squash_merge_footer" ]]; then
squash_merge_footer="${squash_merge_footer}"$'\n' # add linebreaks to space out approver if set
fi
local squash_merge_msg="$title (pull request #$pr_number)
$squash_merge_details$squash_merge_footer$pr_approvers"
shopt -s extglob
squash_merge_msg=${squash_merge_msg%%*($'\n')} # remove all trailing newlines
squash_merge_msg=${squash_merge_msg##*($'\n')} # remove all leading newlines
shopt -u extglob
echo "$squash_merge_msg"
}
ACTION=$1 || true
ACTION=${ACTION:="help"}
if [[ -z "$GIT_REMOTE" && "$ACTION" != "completion" ]]; then
ACTION="help"
fi
if [[ "$#" -ne "0" ]]; then shift; fi
if [[ ! "${ACTION}" =~ ^$ACTION_LIST$ ]]; then
echo "Invalid action [$ACTION]"
action_help
fi
action_"$ACTION" "$@"
cleanup