1
0
Fork 0
mirror of https://code.forgejo.org/actions/cascading-pr synced 2025-03-14 22:36:58 +01:00

use ref instead of sha

This commit is contained in:
Earl Warren 2023-10-24 19:40:35 +02:00
parent a69f5a0ce4
commit b15fc5caaf
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -147,35 +147,25 @@ function pr_number() {
pr $1 | jq --raw-output .number
}
function pr_sha() {
pr_get $1
merged=$(pr $1 | jq --raw-output .merged)
if "$merged"; then
pr $1 | jq --raw-output .merge_commit_sha
else
pr $1 | jq --raw-output .head.sha
fi
}
function pr_merged() {
pr_get $1
pr $1 | jq --raw-output .merged
}
function upsert_clone() {
local direction=$1 ref="$2" sha="$3" clone=$4
local direction=$1 ref="$2" clone=$3
if ! test -d $TMPDIR/$direction; then
git -c credential.helper="store --file=$TMPDIR/$direction.git-credentials" clone $clone $TMPDIR/$direction
fi
(
cd $TMPDIR/$direction
if test "$ref"; then
git switch -c $direction origin/$ref
fi
if test "$sha"; then
git switch -c $direction $sha
if [[ "$ref" =~ ^refs/ ]] ; then
git fetch origin +$ref:$ref
else
ref=origin/$ref
fi
git checkout -b $direction $ref
git config credential.helper "store --file=$TMPDIR/$direction.git-credentials"
git config user.email cascading-pr@example.com
git config user.name cascading-pr
@ -212,8 +202,8 @@ function wait_destination_ci() {
}
function update() {
upsert_clone origin "${options[origin_head]}" "${options[origin_sha]}" ${options[origin_clone]}
upsert_clone destination "${options[destination_head]}" "${options[destination_sha]}" ${options[destination_clone]}
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
@ -243,8 +233,7 @@ function finalize_options() {
options[origin_scheme]=$(scheme ${options[origin_url]})
options[origin_host_port]=$(host_port ${options[origin_url]})
set_clone origin
options[origin_head]=
options[origin_sha]=$(pr_sha origin)
options[origin_head]=refs/pull/${options[origin_pr]}/head
options[destination_api]=${options[destination_url]}/api/v1/repos/${options[destination_repo]}
options[destination_scheme]=$(scheme ${options[destination_url]})
options[destination_host_port]=$(host_port ${options[destination_url]})
@ -252,7 +241,6 @@ function finalize_options() {
options[destination_base]=${options[destination_branch]}
: ${options[prefix]:=${options[origin_repo]}}
options[destination_head]=${options[prefix]}-${options[origin_pr]}
options[destination_sha]=
}
function run() {