mirror of
https://code.forgejo.org/actions/cascading-pr.git
synced 2025-06-28 04:43:44 +00:00
run the update script from the default branch
Fixes: https://code.forgejo.org/actions/cascading-pr/issues/9
This commit is contained in:
parent
39c71c3f40
commit
277569106a
6 changed files with 87 additions and 23 deletions
|
@ -26,6 +26,13 @@ function repo_curl() {
|
|||
DOT=$TMPDIR/$repo forgejo-curl.sh "$@"
|
||||
}
|
||||
|
||||
function default_branch() {
|
||||
local direction=$1
|
||||
|
||||
repo_curl ${options[${direction}_repo]} api_json ${options[${direction}_api]} > $TMPDIR/$direction.json
|
||||
jq --raw-output .default_branch < $TMPDIR/$direction.json
|
||||
}
|
||||
|
||||
function exists_branch() {
|
||||
local direction=$1
|
||||
|
||||
|
@ -153,6 +160,11 @@ function pr_merged() {
|
|||
pr $1 | jq --raw-output .merged
|
||||
}
|
||||
|
||||
function pr_from_fork() {
|
||||
pr_get $1
|
||||
pr $1 | jq --raw-output .head.repo.fork
|
||||
}
|
||||
|
||||
function upsert_clone() {
|
||||
local direction=$1 ref="$2" clone=$3
|
||||
|
||||
|
@ -206,8 +218,21 @@ function update() {
|
|||
upsert_clone origin "${options[origin_head]}" ${options[origin_clone]}
|
||||
upsert_clone destination "${options[destination_head]}" ${options[destination_clone]}
|
||||
(
|
||||
cd $TMPDIR/origin
|
||||
${options[update]} $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin-pr.json
|
||||
local update=${options[update]}
|
||||
if ! [[ "$update" =~ ^/ ]] ; then
|
||||
local d
|
||||
if $(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
|
||||
git -C $TMPDIR/origin worktree add $d $default_branch
|
||||
else
|
||||
d=$TMPDIR/origin
|
||||
fi
|
||||
update=$d/$update
|
||||
fi
|
||||
cd $TMPDIR
|
||||
$update $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin $TMPDIR/origin-pr.json
|
||||
)
|
||||
push destination ${options[destination_head]} ${options[destination_clone]}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue