2023-06-28 02:34:17 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Specify the PR URL"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
PR_URL="$1"
|
|
|
|
|
2023-10-16 07:15:53 +02:00
|
|
|
# sets the upstream metadata for `gh pr status`
|
|
|
|
gh pr checkout "$PR_URL"
|
|
|
|
|
|
|
|
|
2023-06-28 02:34:17 +02:00
|
|
|
# are we good?
|
2023-10-16 07:15:53 +02:00
|
|
|
echo "Checking Conclusions"
|
2023-06-28 02:34:17 +02:00
|
|
|
CONCLUSIONS="$(gh pr status --json statusCheckRollup | jq '.currentBranch | .[] | .[] | select(.conclusion != "SUCCESS") | select(.conclusion != "NEUTRAL")| {status: .status, workfFlowName: .workFlowName, conclusion: .conclusion}')"
|
|
|
|
|
2023-10-16 07:15:53 +02:00
|
|
|
|
2023-06-28 02:34:17 +02:00
|
|
|
|
|
|
|
if [ "$(echo "${CONCLUSIONS}" | wc -l)" -eq 0 ]; then
|
|
|
|
gh pr review --approve "$PR_URL"
|
|
|
|
else
|
|
|
|
echo "Already running or failed: ${CONCLUSIONS}";
|
|
|
|
fi
|
2023-10-16 07:15:53 +02:00
|
|
|
|
|
|
|
if [ "${APPROVED}" != "APPROVED" ]; then
|
|
|
|
echo "PR isn't approved!"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check approval
|
|
|
|
echo "Checking if already approved...."
|
|
|
|
APPROVED="$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)"
|