mirror of
https://code.forgejo.org/actions/cascading-pr
synced 2025-03-15 06:46:59 +01:00
cosmetic refactor
This commit is contained in:
parent
f325820c5a
commit
78e88b2910
1 changed files with 15 additions and 11 deletions
|
@ -25,20 +25,24 @@ function repo_curl() {
|
|||
}
|
||||
|
||||
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() {
|
||||
if ! $(exists_branch) ; then
|
||||
log_info "branch ${options[destination_head]} does not exists"
|
||||
local direction=$1
|
||||
|
||||
if ! $(exists_branch $direction) ; then
|
||||
log_info "branch ${options[${direction}_head]} does not exists"
|
||||
return
|
||||
fi
|
||||
repo_curl ${options[destination_repo]} api_json -X DELETE ${options[destination_api]}/branches/${options[destination_head]}
|
||||
log_info "branch ${options[destination_head]} deleted"
|
||||
repo_curl ${options[${direction}_repo]} api_json -X DELETE ${options[${direction}_api]}/branches/${options[${direction}_head]}
|
||||
log_info "branch ${options[${direction}_head]} deleted"
|
||||
}
|
||||
|
||||
function upsert_branch() {
|
||||
if $(exists_branch) ; then
|
||||
function upsert_destination_branch() {
|
||||
if $(exists_branch destination) ; then
|
||||
log_info "branch ${options[destination_head]} already exists"
|
||||
return
|
||||
fi
|
||||
|
@ -60,7 +64,7 @@ function pr_destination_body() {
|
|||
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)
|
||||
state=$(pr_state destination)
|
||||
if test "$url" != "null" -a "$state" = "open"; then
|
||||
|
@ -87,7 +91,7 @@ function close_pr() {
|
|||
log_info "closing $(pr_url ${direction})"
|
||||
local number=$(pr_number $direction)
|
||||
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
|
||||
log_info "no open PR found"
|
||||
fi
|
||||
|
@ -220,8 +224,8 @@ function run() {
|
|||
open)
|
||||
log_info "PR is open, update or create the cascade branch and PR"
|
||||
repo_login ${options[destination_repo]}
|
||||
upsert_branch
|
||||
upsert_pr
|
||||
upsert_destination_branch
|
||||
upsert_destination_pr
|
||||
repo_login ${options[origin_repo]}
|
||||
update
|
||||
wait_destination_ci $(cat $TMPDIR/destination.sha)
|
||||
|
|
Loading…
Add table
Reference in a new issue