From 18fbf900ed1321e9d3eb9a6f6a70b2522fdc2b0f Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Fri, 27 May 2022 04:25:17 +0300 Subject: [PATCH] Finalize with check-runs only --- files/gitea-merge.sh | 54 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/files/gitea-merge.sh b/files/gitea-merge.sh index 67153b9..39a493c 100755 --- a/files/gitea-merge.sh +++ b/files/gitea-merge.sh @@ -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}