mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-28 04:43:44 +00:00
allow running on a ref instead of a PR
When running from a PR, the ref is the head of the PR in the origin repository. The PR is used to: * display comments about the location of the destination PR * asynchronously close / merge the destination PR when something happens in the origin PR When only the ref is available, the destination PR must be closed and the corresponding branch destroyed immediately after it concludes because there is no convenient way to know what or when something else will happen.
This commit is contained in:
parent
0e9a4e846b
commit
0c3c8b591b
12 changed files with 326 additions and 85 deletions
|
@ -187,7 +187,7 @@ function git_checkout() {
|
|||
(
|
||||
cd $TMPDIR/$direction
|
||||
if [[ "$ref" =~ ^refs/ ]] ; then
|
||||
git fetch ${remote} +$ref:$ref
|
||||
git fetch --update-head-ok ${remote} +$ref:$ref
|
||||
else
|
||||
ref=${remote}/$ref
|
||||
fi
|
||||
|
@ -305,7 +305,7 @@ function update() {
|
|||
local update=${options[update]}
|
||||
if ! [[ "$update" =~ ^/ ]] ; then
|
||||
local d
|
||||
if $(pr_from_fork origin); then
|
||||
if $(origin_has_pr) && $(pr_from_fork origin); then
|
||||
local default_branch=$(default_branch origin)
|
||||
log_info "PR is from a forked repository, using the default branch $default_branch to obtain the update script"
|
||||
d=$TMPDIR/update
|
||||
|
@ -316,7 +316,13 @@ function update() {
|
|||
update=$d/$update
|
||||
fi
|
||||
cd $TMPDIR
|
||||
$update $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin $TMPDIR/origin-pr.json
|
||||
local origin_info
|
||||
if $(origin_has_pr); then
|
||||
origin_info=$TMPDIR/origin-pr.json
|
||||
else
|
||||
origin_info="${options[origin_ref]}"
|
||||
fi
|
||||
$update $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin $origin_info
|
||||
)
|
||||
local remote_head=origin
|
||||
if ${options[destination_is_fork]} ; then
|
||||
|
@ -360,8 +366,7 @@ function finalize_options() {
|
|||
options[origin_scheme]=$(scheme ${options[origin_url]})
|
||||
options[origin_host_port]=$(host_port ${options[origin_url]})
|
||||
set_git_url origin origin_clone ${options[origin_repo]}
|
||||
options[origin_head]=refs/pull/${options[origin_pr]}/head
|
||||
origin_sanity_check
|
||||
set_origin_head
|
||||
|
||||
options[destination_api]=${options[destination_url]}/api/v1/repos/${options[destination_repo]}
|
||||
options[destination_scheme]=$(scheme ${options[destination_url]})
|
||||
|
@ -369,7 +374,7 @@ function finalize_options() {
|
|||
set_git_url destination destination_clone ${options[destination_repo]}
|
||||
options[destination_base]=${options[destination_branch]}
|
||||
: ${options[prefix]:=${options[origin_repo]}}
|
||||
options[destination_head]=${options[prefix]}-${options[origin_pr]}
|
||||
set_destination_head
|
||||
|
||||
if test "${options[destination_fork_repo]}"; then
|
||||
fork_sanity_check
|
||||
|
@ -384,11 +389,39 @@ function finalize_options() {
|
|||
}
|
||||
|
||||
function run() {
|
||||
local state=$(pr_state origin)
|
||||
|
||||
repo_login origin
|
||||
repo_login destination
|
||||
|
||||
if $(origin_has_pr); then
|
||||
run_origin_pr
|
||||
else
|
||||
run_origin_ref
|
||||
fi
|
||||
}
|
||||
|
||||
function run_origin_ref() {
|
||||
log_info "update or create the cascade branch and PR"
|
||||
checkout
|
||||
update
|
||||
local sha=$(sha_pushed destination)
|
||||
if test "$sha" ; then
|
||||
upsert_destination_pr
|
||||
local status
|
||||
if wait_destination_ci "$sha" ; then
|
||||
log_info "cascade PR status successful"
|
||||
status=0
|
||||
else
|
||||
log_info "cascade PR status failed"
|
||||
status=1
|
||||
fi
|
||||
close_pr
|
||||
return $status
|
||||
fi
|
||||
}
|
||||
|
||||
function run_origin_pr() {
|
||||
local state=$(pr_state origin)
|
||||
|
||||
case "$state" in
|
||||
open)
|
||||
log_info "PR is open, update or create the cascade branch and PR"
|
||||
|
@ -455,6 +488,11 @@ function main() {
|
|||
options[origin_pr]=$1
|
||||
shift
|
||||
;;
|
||||
--origin-ref)
|
||||
shift
|
||||
options[origin_ref]=$1
|
||||
shift
|
||||
;;
|
||||
--destination-url)
|
||||
shift
|
||||
options[destination_url]=$1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue