From 09dc15f425e12a4bc27ab8344368ca1bfeb0e4c8 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Tue, 9 Jan 2024 19:47:48 +0100 Subject: [PATCH] close-merge is close and applies to destination-ref as well * workflows that have close-merge need to change to close * the behavior for when origin-pr is set does not change * the behavior for when origin-ref is set is to honor close instead of always closing the PR --- README.md | 2 +- action.yml | 6 +++--- cascading-pr.sh | 13 ++++++++----- tests/origin-branch/.forgejo/workflows/test.yml | 1 + .../.forgejo/workflows/test.yml | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0dce097..5ca5928 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ not exist, it is created. | destination-token | a token with write permission on destination-repo | `true` | | | update | path to the script to update the content of the cascading PR | `true` | | | prefix | prefix of the branch from which the cascading PR is created on {destination-repo} or {destination-fork-repo} (default to {origin-repo}) | `false` | | -| close-merge | if true the cascading PR will be closed and the branch deleted when the PR is merged | `false` | false | +| close | if true the cascading PR will be closed and the branch deleted when the PR is merged | `false` | false | | verbose | if true print verbose information | `false` | false | | debug | if true print debug information | `false` | false | diff --git a/action.yml b/action.yml index 7897e12..b13fbd0 100644 --- a/action.yml +++ b/action.yml @@ -103,8 +103,8 @@ inputs: required: true prefix: description: 'prefix of the branch from which the cascading PR is created on {destination-repo} or {destination-fork-repo} (default to {origin-repo})' - close-merge: - description: 'if true the cascading PR will be closed and the branch deleted when the PR is merged' + close: + description: 'if true the cascading PR will be closed and the branch deleted when (i) the {origin-pr} is merged or (ii) when the cascading PR status is success if {origin-ref} is set' default: false verbose: description: 'if true print verbose information' @@ -145,5 +145,5 @@ runs: --destination-branch "${{ inputs.destination-branch }}" \ --update "${{ inputs.update }}" \ --prefix "${{ inputs.prefix }}" \ - --close-merge "${{ inputs.close-merge }}" \ + --close "${{ inputs.close }}" \ run diff --git a/cascading-pr.sh b/cascading-pr.sh index 34722b5..babe8c0 100755 --- a/cascading-pr.sh +++ b/cascading-pr.sh @@ -385,7 +385,7 @@ function finalize_options() { options[destination_is_fork]=false fi - : ${options[close_merge]:=false} + : ${options[close]:=false} } function run() { @@ -414,7 +414,10 @@ function run_origin_ref() { log_info "cascade PR status failed" status=1 fi - close_pr + if "${options[close]}" ; then + log_info "close the cascade PR and remove the branch" + close_pr + fi return $status fi } @@ -436,7 +439,7 @@ function run_origin_pr() { ;; closed) if "$(pr_merged origin)"; then - if "${options[close_merge]}" ; then + if "${options[close]}" ; then log_info "PR is merged, close the cascade PR and remove the branch" close_pr else @@ -528,9 +531,9 @@ function main() { options[prefix]=$1 shift ;; - --close-merge) + --close) shift - options[close_merge]=$1 + options[close]=$1 shift ;; *) diff --git a/tests/origin-branch/.forgejo/workflows/test.yml b/tests/origin-branch/.forgejo/workflows/test.yml index 2d1ce52..acb584b 100644 --- a/tests/origin-branch/.forgejo/workflows/test.yml +++ b/tests/origin-branch/.forgejo/workflows/test.yml @@ -16,5 +16,6 @@ jobs: destination-repo: user2/destinationrepo destination-branch: main destination-token: ${{ secrets.DESTINATION_TOKEN }} + close: true update: ./upgraded debug: true diff --git a/tests/originrepo-close-merge/.forgejo/workflows/test.yml b/tests/originrepo-close-merge/.forgejo/workflows/test.yml index a12cb81..fa2c959 100644 --- a/tests/originrepo-close-merge/.forgejo/workflows/test.yml +++ b/tests/originrepo-close-merge/.forgejo/workflows/test.yml @@ -21,5 +21,5 @@ jobs: destination-branch: main destination-token: ${{ secrets.DESTINATION_TOKEN }} update: ./upgraded - close-merge: true + close: true debug: true