A basic fragile script for merging a gitea PR checking only check-runs
This commit is contained in:
parent
3c4061b37e
commit
514f6433b2
93
files/gitea-merge.sh
Executable file
93
files/gitea-merge.sh
Executable file
|
@ -0,0 +1,93 @@
|
|||
#!/bin/bash
|
||||
|
||||
REPOAPIURL=https://git.bitmessage.org/api/v1/repos/Bitmessage/PyBitmessage
|
||||
upstream="v0.6"
|
||||
|
||||
if [ -z "${1}" ]; then
|
||||
echo "Please specify a credential string"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${2}" ]; then
|
||||
echo "No PR# specified, here is a list:"
|
||||
curl -s -X GET -u ${1} ${REPOAPIURL}/pulls \
|
||||
| jq '.[] | select(.state == "open") | .number, .title' | paste - -
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 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')
|
||||
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"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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' | tr -d '"')
|
||||
branch=(echo $pr | jq '.base.ref' | tr -d '"')
|
||||
url=$(echo $pr | jq '.url' | tr -d '"')
|
||||
|
||||
|
||||
# Return non-zero status if have a check with conclusion other than "success"
|
||||
pr_status () {
|
||||
# Need Instead compare
|
||||
# required:
|
||||
# curl -s -X GET $branch | jq '.protection.required_status_checks.contexts'
|
||||
# done:
|
||||
# curl -s -X GET ${REPOAPIURL}/commits/${commit}/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
|
||||
}
|
||||
|
||||
# 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 -u ${3} -X POST \
|
||||
# -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}
|
Loading…
Reference in New Issue
Block a user