From 9d21e0994e5ecfd2acc7ee9a551f974c8f049093 Mon Sep 17 00:00:00 2001 From: Stuart Harrison Date: Mon, 10 May 2021 19:02:59 +0100 Subject: [PATCH] Allow PR_NUMBER to be set externally (#76) --- README.md | 11 +++++++++++ entrypoint.sh | 17 ++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 83089b3..2667b7f 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,17 @@ Example GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} ``` +You can also optionally specify the PR number of the branch to rebase, +if the action you're running doesn't directly refer to a specific +pull request: + +```yaml + - name: Automatic Rebase + uses: cirrus-actions/rebase@1.4 + env: + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} + PR_NUMBER: 1245 +``` ## Restricting who can call the action diff --git a/entrypoint.sh b/entrypoint.sh index 204467e..7f2ce2c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,14 +2,17 @@ set -e -PR_NUMBER=$(jq -r ".pull_request.number" "$GITHUB_EVENT_PATH") -if [[ "$PR_NUMBER" == "null" ]]; then - PR_NUMBER=$(jq -r ".issue.number" "$GITHUB_EVENT_PATH") -fi -if [[ "$PR_NUMBER" == "null" ]]; then - echo "Failed to determine PR Number." - exit 1 +if [ -z "$PR_NUMBER" ]; then + PR_NUMBER=$(jq -r ".pull_request.number" "$GITHUB_EVENT_PATH") + if [[ "$PR_NUMBER" == "null" ]]; then + PR_NUMBER=$(jq -r ".issue.number" "$GITHUB_EVENT_PATH") + fi + if [[ "$PR_NUMBER" == "null" ]]; then + echo "Failed to determine PR Number." + exit 1 + fi fi + echo "Collecting information about PR #$PR_NUMBER of $GITHUB_REPOSITORY..." if [[ -z "$GITHUB_TOKEN" ]]; then