From 604fda4f4254216e3b564d60fe27d68017756558 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Mon, 15 May 2023 14:37:34 -0600 Subject: [PATCH] fix: bug retrieving the current branch name on pull request review event (#235) --- .github/workflows/test.yml | 11 ++++++----- action.yml | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 17942a1..605e0c3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,7 @@ on: - '*' branches: - main + pull_request_review: pull_request_target: pull_request: branches: @@ -41,22 +42,22 @@ jobs: echo "Is Tag: ${{ steps.branch-name.outputs.is_tag }}" echo "Current tag: ${{ steps.branch-name.outputs.tag }}" - name: Test is_default output for pull request - if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'false' + if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'false' run: | echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}" exit 1 - name: Test is_default output for non pull request - if: github.event_name != 'pull_request' && github.event_name != 'pull_request_target' && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'true' + if: "!contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'true'" run: | echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}" exit 1 - name: Test base_ref_branch output - if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.base_ref_branch + if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.base_ref_branch run: | echo "Base ref unset: ${{ steps.branch-name.outputs.base_ref_branch }}" exit 1 - name: Test head_ref output - if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.head_ref_branch + if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.head_ref_branch run: | echo "Head ref unset: ${{ steps.branch-name.outputs.head_ref_branch }}" exit 1 @@ -66,7 +67,7 @@ jobs: echo "Ref unset: ${{ steps.branch-name.outputs.ref_branch }}" exit 1 - name: Test current_branch output for pull_request or pull_request_target event. - if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.current_branch + if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.current_branch run: | echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}" exit 1 diff --git a/action.yml b/action.yml index a6e44e2..d533e70 100644 --- a/action.yml +++ b/action.yml @@ -40,8 +40,8 @@ runs: run: | # "Set branch names..." if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then - BASE_REF=$(printf "%q" "${{ github.base_ref }}") - HEAD_REF=$(printf "%q" "${{ github.head_ref }}") + BASE_REF=$(printf "%q" "${{ github.event.pull_request.base.ref || github.base_ref }}") + HEAD_REF=$(printf "%q" "${{ github.event.pull_request.head.ref || github.head_ref }}") REF=$(printf "%q" "${{ github.ref }}") BASE_REF=${BASE_REF/refs\/heads\//} @@ -73,7 +73,7 @@ runs: run: | # "Set the current branch name..." if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then - if [[ ${{ github.event_name }} == 'pull_request' || ${{ github.event_name }} == 'pull_request_target' ]]; then + if [[ ${{ github.event_name }} == *"pull_request"* ]]; then if [[ -z "$GITHUB_OUTPUT" ]]; then echo "::set-output name=current_branch::${{ steps.branch.outputs.head_ref_branch }}" else