diff --git a/cascading-pr.sh b/cascading-pr.sh index 977a8ff..3b42f33 100755 --- a/cascading-pr.sh +++ b/cascading-pr.sh @@ -108,6 +108,10 @@ function pr_head() { pr $1 | jq --raw-output .head.ref } +function pr_merged() { + pr $1 | jq --raw-output .merged +} + function upsert_clone() { local direction=$1 branch=$2 clone=$3 @@ -154,7 +158,7 @@ function update() { ( cd $TMPDIR/origin ls -l $TMPDIR/destination - ${options[update]} $TMPDIR/destination + ${options[update]} $TMPDIR/destination $TMPDIR/destination-pr.json $TMPDIR/origin-pr.json ) push destination ${options[destination_head]} ${options[destination_clone]} } @@ -188,9 +192,17 @@ function run() { wait_destination_ci $(cat $TMPDIR/destination.sha) ;; closed) - log_info "PR is closed, close the cascade PR and remove the branch" - repo_login ${options[destination_repo]} - close_pr destination + if "$(pr_merged origin)"; then + log_info "PR was merged, update the cascade PR" + repo_login ${options[destination_repo]} + pr origin + pr destination + update + else + log_info "PR is closed, close the cascade PR and remove the branch" + repo_login ${options[destination_repo]} + close_pr destination + fi ;; *) log_info "state '$state', do nothing" diff --git a/tests/originrepo/upgraded b/tests/originrepo/upgraded index ee39223..8b37734 100755 --- a/tests/originrepo/upgraded +++ b/tests/originrepo/upgraded @@ -1,5 +1,13 @@ #!/bin/bash -destination="$1" +set -ex -date +%s > $destination/last +destination_checkout="$1" +destination_pr_json="$2" +origin_pr_json="$3" + +test -d $destination_checkout +test -f $destination_pr_json +test -f $origin_pr_json + +date +%s > $destination_checkout/last diff --git a/tests/run.sh b/tests/run.sh index fcaef1a..264eae2 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -51,6 +51,12 @@ function close_pull_request() { done } +function merge_pull_request() { + forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/originrepo/pulls | jq --raw-output '.[] | .number' | while read pr ; do + forgejo-curl.sh api_json --data-raw '{"Do":"merge"}' ${options[url]}/api/v1/repos/user1/originrepo/pulls/$pr/merge + done +} + function create_pull_request() { forgejo-curl.sh api_json ${options[url]}/api/v1/repos/user1/originrepo/pulls | jq --raw-output '.[] | .number' | while read pr ; do forgejo-curl.sh api_json -X DELETE ${options[url]}/api/v1/repos/user1/originrepo/issues/$pr @@ -96,12 +102,20 @@ function run() { push_self + # + # create & close + # create_pull_request - + wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha) + close_pull_request wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha) - close_pull_request - + # + # create & merge + # + create_pull_request + wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha) + merge_pull_request wait_success ${options[url]}/api/v1/repos/user1/originrepo $(cat $TMPDIR/originrepo.sha) }