Skip to content

Commit 604fda4

Browse files
authored
fix: bug retrieving the current branch name on pull request review event (#235)
1 parent d53a4f5 commit 604fda4

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- '*'
77
branches:
88
- main
9+
pull_request_review:
910
pull_request_target:
1011
pull_request:
1112
branches:
@@ -41,22 +42,22 @@ jobs:
4142
echo "Is Tag: ${{ steps.branch-name.outputs.is_tag }}"
4243
echo "Current tag: ${{ steps.branch-name.outputs.tag }}"
4344
- name: Test is_default output for pull request
44-
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'
45+
if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'false'
4546
run: |
4647
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
4748
exit 1
4849
- name: Test is_default output for non pull request
49-
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'
50+
if: "!contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && steps.branch-name.outputs.is_default != 'true'"
5051
run: |
5152
echo "Is default is invalid: ${{ steps.branch-name.outputs.is_default }}"
5253
exit 1
5354
- name: Test base_ref_branch output
54-
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
55+
if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.base_ref_branch
5556
run: |
5657
echo "Base ref unset: ${{ steps.branch-name.outputs.base_ref_branch }}"
5758
exit 1
5859
- name: Test head_ref output
59-
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
60+
if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.head_ref_branch
6061
run: |
6162
echo "Head ref unset: ${{ steps.branch-name.outputs.head_ref_branch }}"
6263
exit 1
@@ -66,7 +67,7 @@ jobs:
6667
echo "Ref unset: ${{ steps.branch-name.outputs.ref_branch }}"
6768
exit 1
6869
- name: Test current_branch output for pull_request or pull_request_target event.
69-
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
70+
if: contains(github.event_name, 'pull_request') && steps.branch-name.outputs.is_tag == 'false' && !steps.branch-name.outputs.current_branch
7071
run: |
7172
echo "Current branch unset: ${{ steps.branch-name.outputs.current_branch }}"
7273
exit 1

action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ runs:
4040
run: |
4141
# "Set branch names..."
4242
if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then
43-
BASE_REF=$(printf "%q" "${{ github.base_ref }}")
44-
HEAD_REF=$(printf "%q" "${{ github.head_ref }}")
43+
BASE_REF=$(printf "%q" "${{ github.event.pull_request.base.ref || github.base_ref }}")
44+
HEAD_REF=$(printf "%q" "${{ github.event.pull_request.head.ref || github.head_ref }}")
4545
REF=$(printf "%q" "${{ github.ref }}")
4646
4747
BASE_REF=${BASE_REF/refs\/heads\//}
@@ -73,7 +73,7 @@ runs:
7373
run: |
7474
# "Set the current branch name..."
7575
if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then
76-
if [[ ${{ github.event_name }} == 'pull_request' || ${{ github.event_name }} == 'pull_request_target' ]]; then
76+
if [[ ${{ github.event_name }} == *"pull_request"* ]]; then
7777
if [[ -z "$GITHUB_OUTPUT" ]]; then
7878
echo "::set-output name=current_branch::${{ steps.branch.outputs.head_ref_branch }}"
7979
else

0 commit comments

Comments
 (0)