Skip to content

Commit 26a38dd

Browse files
authored
feat: support workflow_dispatch (#12)
* feat: support workflow_dispatch Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * remove pull_request_target test Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * embed branch-based-query within fallback Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * docs include `workflow_dispatch` Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --------- Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>
1 parent ff9cab7 commit 26a38dd

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Supported event triggers:
1010
- `issue_comment`
1111
- `merge_group`
1212
- `push`
13+
- `workflow_dispatch`
1314
- `pull_request` (of course!)
1415

1516
</br>

action.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: Get Current PR Data
33
author: Rishav Dhar (@rdhar)
4-
description: Get current PR data from any event trigger, including: issue_comment, merge_group, and push.
4+
description: "Get current PR data from any event trigger, including: issue_comment, merge_group, push, and workflow_dispatch."
55

66
runs:
77
using: composite
@@ -16,6 +16,9 @@ runs:
1616
- id: data
1717
shell: bash
1818
run: |
19+
# Fallback on empty string if the branch is not found.
20+
branch=${{ github.ref_name || github.head_ref || github.ref || '' }}
21+
1922
# Get PR number using GitHub API for different event triggers.
2023
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
2124
# List PRs associated with the commit, then get the PR number from the head ref or the latest PR.
@@ -25,11 +28,10 @@ runs:
2528
# Get the PR number by parsing the ref name.
2629
number=$(echo "${GITHUB_REF_NAME}" | sed -n 's/.*pr-\([0-9]*\)-.*/\1/p')
2730
else
28-
# Fallback on 0 if the PR number is not found.
29-
number=${{ github.event.number || github.event.issue.number || 0 }}
31+
# Get the PR number from branch name, otherwise fallback on 0 if the PR number is not found.
32+
number=$(gh api /repos/{owner}/{repo}/pulls --header "$GH_API" --method GET --field per_page=100 --field head="${branch}" | jq .[0].number) || ${{ github.event.number || github.event.issue.number || 0 }}
3033
fi
31-
# Fallback on empty string if the branch is not found.
32-
branch=${{ github.ref_name || github.head_ref || github.ref || '' }}
34+
3335
echo "branch=$branch" >> "$GITHUB_OUTPUT"
3436
echo "number=$number" >> "$GITHUB_OUTPUT"
3537

0 commit comments

Comments
 (0)