-
Notifications
You must be signed in to change notification settings - Fork 2
/
mergeAllDependabotPRs.sh
executable file
·47 lines (35 loc) · 1.41 KB
/
mergeAllDependabotPRs.sh
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
#!/bin/bash
timestamp() {
date +"%Y-%m-%d"
}
ORG=al-mabsut
REPO=muslimah
PR_URL=https://github.com/$ORG/$REPO/pull/
ts=$(timestamp)
branchName="combine-all-dependabot-prs-$ts-$((1000 + RANDOM % 9999))"
NL=$'\n'
dependabotPRs=$(gh pr list --repo $ORG/$REPO --json number,headRefName | jq -r '.[] | select(.headRefName|test("^(dependabot\/).*$"))')
dependabotPRNumbers="${NL}$(echo $dependabotPRs | jq -r '.number')"
dependabotPRLinks=${dependabotPRNumbers//${NL}/${NL}* $PR_URL}
dependabotPRBranchNames=$(echo $dependabotPRs | jq -r '.headRefName')
echo "Obtain all dependabot PR branches: \n$(gh pr list --repo $ORG/$REPO --json commits | jq -r '.[] .commits | .[] | select(.messageHeadline|test("^(Dependabot).*$")) | [.oid, .messageHeadline] | @tsv' | column -ts $'\t')"
dependabotPRBranchNames=${dependabotPRBranchNames//$'\n'/ } # Replace all newlines with spaces
echo "Checking out branch: $branchName"
git checkout -b $branchName
echo "Pull all dependabot PRs into this branch"
if ! git pull origin $dependabotPRBranchNames --no-edit --no-rebase; then
echo "Merge failed due to conflicts."
git checkout -f
git checkout -
git branch -D $branchName
exit 1
fi
git commit --amend -m "Combine all dependabot-prs until $ts
This commit combines all the following PRs: $dependabotPRLinks
"
echo "Push branch to remote"
git push origin $branchName
sleep 1
echo "Create PR"
gh pr create -f -a @me
echo "All done"