mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-28 04:43:44 +00:00
remove branches when closing a cascade PR from a fork
Fixes: https://code.forgejo.org/actions/cascading-pr/issues/17
This commit is contained in:
parent
09dc15f425
commit
417a1ecac9
2 changed files with 36 additions and 13 deletions
|
@ -44,21 +44,22 @@ function destination_updated_at() {
|
|||
jq --raw-output .updated_at < $TMPDIR/updated_at.json
|
||||
}
|
||||
|
||||
function exists_branch() {
|
||||
local direction=$1
|
||||
function delete_branch_destination() {
|
||||
local branch=${options[destination_head]}
|
||||
local repo=${options[destination_repo]}
|
||||
local api=${options[destination_api]}
|
||||
|
||||
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]}/branches/${options[${direction}_head]} >& /dev/null
|
||||
}
|
||||
if ${options[destination_is_fork]} ; then
|
||||
repo=${options[destination_fork_repo]}
|
||||
api=${options[destination_fork_api]}
|
||||
fi
|
||||
|
||||
function delete_branch() {
|
||||
local direction=$1
|
||||
|
||||
if ! $(exists_branch $direction) ; then
|
||||
log_info "branch ${options[${direction}_head]} does not exists"
|
||||
if ! repo_curl ${options[destination_repo]} api_json $api/branches/$branch >& /dev/null ; then
|
||||
log_info "branch $branch does not exists in $repo"
|
||||
return
|
||||
fi
|
||||
repo_curl ${options[${direction}_repo]} api_json -X DELETE ${options[${direction}_api]}/branches/${options[${direction}_head]}
|
||||
log_info "branch ${options[${direction}_head]} deleted"
|
||||
repo_curl ${options[destination_repo]} api_json -X DELETE $api/branches/$branch
|
||||
log_info "branch $branch deleted in $repo"
|
||||
}
|
||||
|
||||
function pr_origin_comment_body() {
|
||||
|
@ -115,7 +116,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 ${direction}
|
||||
delete_branch_destination
|
||||
else
|
||||
log_info "no open PR found"
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue