mirror of
https://code.forgejo.org/actions/cascading-pr
synced 2025-03-15 14:54:40 +01:00
use ref instead of sha
This commit is contained in:
parent
a69f5a0ce4
commit
b15fc5caaf
1 changed files with 9 additions and 21 deletions
|
@ -147,35 +147,25 @@ function pr_number() {
|
||||||
pr $1 | jq --raw-output .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() {
|
function pr_merged() {
|
||||||
pr_get $1
|
pr_get $1
|
||||||
pr $1 | jq --raw-output .merged
|
pr $1 | jq --raw-output .merged
|
||||||
}
|
}
|
||||||
|
|
||||||
function upsert_clone() {
|
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
|
if ! test -d $TMPDIR/$direction; then
|
||||||
git -c credential.helper="store --file=$TMPDIR/$direction.git-credentials" clone $clone $TMPDIR/$direction
|
git -c credential.helper="store --file=$TMPDIR/$direction.git-credentials" clone $clone $TMPDIR/$direction
|
||||||
fi
|
fi
|
||||||
(
|
(
|
||||||
cd $TMPDIR/$direction
|
cd $TMPDIR/$direction
|
||||||
if test "$ref"; then
|
if [[ "$ref" =~ ^refs/ ]] ; then
|
||||||
git switch -c $direction origin/$ref
|
git fetch origin +$ref:$ref
|
||||||
fi
|
else
|
||||||
if test "$sha"; then
|
ref=origin/$ref
|
||||||
git switch -c $direction $sha
|
|
||||||
fi
|
fi
|
||||||
|
git checkout -b $direction $ref
|
||||||
git config credential.helper "store --file=$TMPDIR/$direction.git-credentials"
|
git config credential.helper "store --file=$TMPDIR/$direction.git-credentials"
|
||||||
git config user.email cascading-pr@example.com
|
git config user.email cascading-pr@example.com
|
||||||
git config user.name cascading-pr
|
git config user.name cascading-pr
|
||||||
|
@ -212,8 +202,8 @@ function wait_destination_ci() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
upsert_clone origin "${options[origin_head]}" "${options[origin_sha]}" ${options[origin_clone]}
|
upsert_clone origin "${options[origin_head]}" ${options[origin_clone]}
|
||||||
upsert_clone destination "${options[destination_head]}" "${options[destination_sha]}" ${options[destination_clone]}
|
upsert_clone destination "${options[destination_head]}" ${options[destination_clone]}
|
||||||
(
|
(
|
||||||
cd $TMPDIR/origin
|
cd $TMPDIR/origin
|
||||||
${options[update]} $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin-pr.json
|
${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_scheme]=$(scheme ${options[origin_url]})
|
||||||
options[origin_host_port]=$(host_port ${options[origin_url]})
|
options[origin_host_port]=$(host_port ${options[origin_url]})
|
||||||
set_clone origin
|
set_clone origin
|
||||||
options[origin_head]=
|
options[origin_head]=refs/pull/${options[origin_pr]}/head
|
||||||
options[origin_sha]=$(pr_sha origin)
|
|
||||||
options[destination_api]=${options[destination_url]}/api/v1/repos/${options[destination_repo]}
|
options[destination_api]=${options[destination_url]}/api/v1/repos/${options[destination_repo]}
|
||||||
options[destination_scheme]=$(scheme ${options[destination_url]})
|
options[destination_scheme]=$(scheme ${options[destination_url]})
|
||||||
options[destination_host_port]=$(host_port ${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[destination_base]=${options[destination_branch]}
|
||||||
: ${options[prefix]:=${options[origin_repo]}}
|
: ${options[prefix]:=${options[origin_repo]}}
|
||||||
options[destination_head]=${options[prefix]}-${options[origin_pr]}
|
options[destination_head]=${options[prefix]}-${options[origin_pr]}
|
||||||
options[destination_sha]=
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function run() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue