Finalize with check-runs only

This commit is contained in:
Lee Miller 2022-05-27 04:25:17 +03:00
parent 36e75b1b69
commit 18fbf900ed
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
1 changed files with 43 additions and 11 deletions

View File

@ -10,12 +10,13 @@ fi
if [ -z "${2}" ]; then
echo "No PR# specified, here is a list:"
curl -s --request GET -u ${1} ${REPOAPIURL}/pulls \
curl -s -X GET -u ${1} ${REPOAPIURL}/pulls \
| jq '.[] | select(.state == "open") | .number, .title' | paste - -
exit 1
fi
pr=$(curl -s --request GET -u ${1} ${REPOAPIURL}/pulls/${2})
# Read PR and parse its fields
pr=$(curl -s -X GET -u ${1} ${REPOAPIURL}/pulls/${2})
branch=$(echo $pr | jq '.head | (.repo.ssh_url + " " + .label)' | tr -d '"')
title=$(echo $pr | jq '.title')
@ -24,10 +25,13 @@ body=$(echo $pr | jq '.body')
echo "Merging PR ${2}"
# Merge PR branch into the newly created branch and push it to github
git checkout v0.6
git branch -d gitea-${2}
git checkout -b gitea-${2} v0.6
git pull ${branch} || exit 1
git push --set-upstream origin gitea-${2}
git checkout v0.6
if [ -z "${3}" ]; then
echo "No github credentials specified, stopping"
@ -38,21 +42,49 @@ head=$(echo ${3} | cut -d: -f1):gitea-${2}
REPOAPIURL=https://api.github.com/repos/Bitmessage/PyBitmessage
# Create PR on github and parse its fields
pr=$(curl -s -u ${3} -X POST \
-H "Accept: application/vnd.github.v3+json" ${REPOAPIURL}/pulls \
-d "{\"title\":${title},\"body\":${body},\"head\":\"${head}\",\"base\":\"${upstream}\"}")
# commit=$(echo $pr | jq '.head.sha')
# url=$(echo $pr | jq '.url')
commit=$(echo $pr | jq '.head.sha' | tr -d '"')
branch=(echo $pr | jq '.base.ref' | tr -d '"')
url=$(echo $pr | jq '.url' | tr -d '"')
# checks=$(
# curl -s --request GET \
# -H "Accept: application/vnd.github.v3+json" \
# ${REPOAPIURL}/commits/${commit}/check-runs)
# sleep 10
# Return non-zero status if have a check with conclusion other than "success"
pr_status () {
checks=$(
curl -s -X GET \
-H "Accept: application/vnd.github.v3+json" \
${REPOAPIURL}/commits/${1}/check-runs)
if [[ \
$(echo $checks | jq \
'(.check_runs | map(select(.conclusion == "success")) | length) == .total_count'\
) != true ]]; then
return 1
fi
}
# echo $checks | jq '(.check_runs | map(select(.conclusion == "success")) | length) == .total_count'
# Invoke pullrequest.sh script if pr_status is 0 within 30 tries in 5 min
for tick in {1..30}; do
sleep 10
pr_status ${commit}
if [[ $? -eq 0 ]]; then
./git-tools.sh mergepullrequest $(curl -s -X GET ${url} | jq '.number')
break
fi
done
# curl -s -X GET ${REPOAPIURL}/commits/${commit}/status
# curl -s -u ${3} -X POST \
# -H "Accept: application/vnd.github.v3+json" $url -d '{"event":"APPROVE"}'
# -H "Accept: application/vnd.github.v3+json" $url/reviews \
# -d '{"event":"APPROVE"}'
# "Can not approve your own pull request"
# Delete branch:
# curl -s -u ${3} -X DELETE -H "Accept: application/vnd.github.v3+json" \
# ${REPOAPIURL}/git/refs/heads/gitea-${2}