From b15fc5caafaac09951f62d90f3f31b69b8535370 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 24 Oct 2023 19:40:35 +0200 Subject: [PATCH] use ref instead of sha --- cascading-pr.sh | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/cascading-pr.sh b/cascading-pr.sh index 08c44a5..bb5a11b 100755 --- a/cascading-pr.sh +++ b/cascading-pr.sh @@ -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() {