-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path6-check-pr-repo.sh
executable file
·81 lines (66 loc) · 2.67 KB
/
6-check-pr-repo.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
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
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. "$SCRIPT_DIR/config/config.ini"
# Need at least 2 args
if [ $# -le 1 ]
then
echo -e "\nUsage: $0 <repo-name> <branch-name> *<target-path>\n"
echo -e "Check the PR in the upstream using the given branch in the origin repo has passed all it's checks\n"
echo -e "repo-name: the valid name of a $REPO_PREFIX repo."
echo -e "branch-name: the name of the new branch to be created."
echo -e "target-path: optional argument specifying the path where the repo should be located. If not specified the current directory will be used.\n"
echo -e "\nNote: it is assumed the repo's were correctly cloned and configured using \"clone-setup-repo(s).sh\""
exit 1
fi
REPO_NAME=$1
BRANCH_NAME=$2
TARGET_PATH=$3
# This will only be set when called from multi-run script
MULTI_RUN=$4
if [ -z "$MULTI_RUN" ]
then
echo -e "Verify PR checks using \"$BRANCH_NAME\" for \"$REPO_PREFIX\" repo: $REPO_NAME\n"
fi
. "$SCRIPT_DIR/helper/functions.sh"
#
# Check all the pre-requisites, if any fail a message will be printed and script will exit
#
TARGET_PATH=$(get_target_path)
check_repo_prefix
check_target_path_exists
check_target_repo_path_exists
#
# Call will exit with a message if the repo is not found in the config file
# Note that we always set UPSTREAM_ORG and BASE_BRANCH to themselves in case they are passed in
#
UPSTREAM_ORG=$UPSTREAM_ORG
BASE_BRANCH=$BASE_BRANCH
FOUND=false
. "$SCRIPT_DIR/helper/find-repo-in-repos-list-file.sh"
#
# Time to check the PR
#
pushd "$TARGET_PATH/$REPO_NAME" > /dev/null 2>&1
git checkout $BRANCH_NAME > /dev/null 2>&1
ORIGIN_USER=`git remote -v | grep origin | grep fetch | awk -F "/" '{print $4}'`
PR_CREATE_OUTPUT=`gh pr create --repo $UPSTREAM_ORG/$REPO_NAME --base $BASE_BRANCH --head $ORIGIN_USER:$BRANCH_NAME --title="test" --body="test" 2>&1`
CREATE_PR_RET=$?
PR_URL=`echo $PR_CREATE_OUTPUT | awk '{print $NF}' | grep https`
popd > /dev/null 2>&1
if [ -z "$PR_URL" ]
then
echo -e "ERROR: PR does not exist for branch \"$BRANCH_NAME\" in \"$REPO_PREFIX\" repo: $REPO_NAME"
else
NUM_CHECKS=`gh pr checks $PR_URL 2>&1 | grep https | wc -l`
TOTAL_PASSES=`gh pr checks $PR_URL 2>&1 | grep https | grep pass | wc -l`
TOTAL_FAILS=`gh pr checks $PR_URL 2>&1 | grep https | grep fail | wc -l`
if [ $NUM_CHECKS -eq $TOTAL_PASSES ]; then
echo "Successully passed all checks, PR ready for merge: $PR_URL, for repo: $REPO_NAME"
else
if [ $TOTAL_FAILS -eq 0 ]; then
echo "WARNING: Wait for checks to finish ($TOTAL_PASSES of $NUM_CHECKS passing) for: $PR_URL, for repo: $REPO_NAME"
else
echo "ERROR: Failure for checks ($TOTAL_FAILS of $NUM_CHECKS failed) for: $PR_URL, for repo: $REPO_NAME"
fi
fi
fi