cosmetic refactor

This commit is contained in:
Earl Warren 2023-10-22 17:45:18 +02:00
parent f325820c5a
commit 78e88b2910
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -25,20 +25,24 @@ function repo_curl() {
} }
function exists_branch() { function exists_branch() {
repo_curl ${options[destination_repo]} api_json ${options[destination_api]}/branches/${options[destination_head]} >& /dev/null local direction=$1
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]}/branches/${options[${direction}_head]} >& /dev/null
} }
function delete_branch() { function delete_branch() {
if ! $(exists_branch) ; then local direction=$1
log_info "branch ${options[destination_head]} does not exists"
if ! $(exists_branch $direction) ; then
log_info "branch ${options[${direction}_head]} does not exists"
return return
fi fi
repo_curl ${options[destination_repo]} api_json -X DELETE ${options[destination_api]}/branches/${options[destination_head]} repo_curl ${options[${direction}_repo]} api_json -X DELETE ${options[${direction}_api]}/branches/${options[${direction}_head]}
log_info "branch ${options[destination_head]} deleted" log_info "branch ${options[${direction}_head]} deleted"
} }
function upsert_branch() { function upsert_destination_branch() {
if $(exists_branch) ; then if $(exists_branch destination) ; then
log_info "branch ${options[destination_head]} already exists" log_info "branch ${options[destination_head]} already exists"
return return
fi fi
@ -60,7 +64,7 @@ function pr_destination_body() {
echo "cascading-pr from ${options[origin_url]}/${options[origin_repo]}/pulls/${options[origin_pr]}" echo "cascading-pr from ${options[origin_url]}/${options[origin_repo]}/pulls/${options[origin_pr]}"
} }
function upsert_pr() { function upsert_destination_pr() {
url=$(pr_url destination) url=$(pr_url destination)
state=$(pr_state destination) state=$(pr_state destination)
if test "$url" != "null" -a "$state" = "open"; then if test "$url" != "null" -a "$state" = "open"; then
@ -87,7 +91,7 @@ function close_pr() {
log_info "closing $(pr_url ${direction})" log_info "closing $(pr_url ${direction})"
local number=$(pr_number $direction) local number=$(pr_number $direction)
repo_curl ${options[${direction}_repo]} api_json -X PATCH --data '{"state":"closed"}' ${options[${direction}_api]}/issues/$number repo_curl ${options[${direction}_repo]} api_json -X PATCH --data '{"state":"closed"}' ${options[${direction}_api]}/issues/$number
delete_branch $(pr_head ${direction}) delete_branch ${direction}
else else
log_info "no open PR found" log_info "no open PR found"
fi fi
@ -220,8 +224,8 @@ function run() {
open) open)
log_info "PR is open, update or create the cascade branch and PR" log_info "PR is open, update or create the cascade branch and PR"
repo_login ${options[destination_repo]} repo_login ${options[destination_repo]}
upsert_branch upsert_destination_branch
upsert_pr upsert_destination_pr
repo_login ${options[origin_repo]} repo_login ${options[origin_repo]}
update update
wait_destination_ci $(cat $TMPDIR/destination.sha) wait_destination_ci $(cat $TMPDIR/destination.sha)