-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge-ami-prs
executable file
·52 lines (36 loc) · 1.97 KB
/
merge-ami-prs
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
#!/bin/bash
USAGE="Merges AMI pull requests in all repositories where such PR exists.\n"
USAGE+="Usage: albert merge-ami-prs"
([[ "$1" == "help" ]] || [[ "$2" == "help" ]] ) && { echo -e "$USAGE"; exit 0; }
MY_DIR="$(dirname "$0")"
source "$MY_DIR/util"
check_access_token
REPO_NAMES=$(get_repos)
echo -e "Merging AMI pull request in $(echo "$REPO_NAMES" | wc -l) repositories\n"
for REPO in $REPO_NAMES; do
PULL_REQUESTS=$(http GET "https://api.github.com/repos/AutoScout24/$REPO/pulls?status=open&access_token=$ACCESS_TOKEN" | jq "map(select(.title | test(\"AMI is updated\")))")
PR_COUNT=$(echo "$PULL_REQUESTS" | jq "length")
# TODO: Get rid of duplication in both if and elif cases
if [[ $PR_COUNT -eq 1 ]]; then
PR_TITLE=$(echo "$PULL_REQUESTS" | jq ".[0].title")
PR_NUMBER=$(echo "$PULL_REQUESTS" | jq ".[0].number")
echo "$(tput bold)$(tput setaf 3)Open AMI PR $PR_NUMBER in $REPO$(tput sgr0)"
echo -e "Going to merge $(tput bold)$PR_TITLE$(tput sgr0) now"
merge_pr $PR_NUMBER
elif [[ $PR_COUNT -gt 1 ]]; then
PR_TITLE=$(echo "$PULL_REQUESTS" | jq ".[0].title")
PR_NUMBER=$(echo "$PULL_REQUESTS" | jq ".[0].number")
echo "$(tput bold)$(tput setaf 3)Open AMI PR $PR_NUMBER in $REPO$(tput sgr0)"
echo -e "Going to merge $(tput bold)$PR_TITLE$(tput sgr0) now"
merge_pr $PR_NUMBER
echo -e "$(tput bold)$(tput setaf 1)More than 1 PR open; will remove other PRs $(tput sgr0)"
PR_NUMBERS_TO_REMOVE=$(echo "$PULL_REQUESTS" | jq ".[1:$PR_COUNT]" | jq ".[].number")
for PR_NUMBER_TO_REMOVE in $PR_NUMBERS_TO_REMOVE; do
echo "$(tput bold)Removing PR with number $PR_NUMBER_TO_REMOVE in $REPO $(tput sgr0)"
http PATCH "https://api.github.com/repos/AutoScout24/$REPO/pulls/$PR_NUMBER_TO_REMOVE?access_token=$ACCESS_TOKEN" state=closed 1> /dev/null
done;
echo
else
echo -e "$(tput bold)$REPO$(tput sgr0): no PR found\n"
fi
done;