Skip to content

Commit 6b647a4

Browse files
authored
feat: branch output (#9)
* docs: wording scope Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * add `branch` output Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * add branch action output Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * output branch from step Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * default `GITHUB_REF_NAME` Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * clarify fallback Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * reorder branch outputs Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * add `github.ref` Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> * add `github.ref_name` fallback Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com> --------- Signed-off-by: Rishav Dhar <19497993+rdhar@users.noreply.github.com>
1 parent ee21b53 commit 6b647a4

3 files changed

Lines changed: 22 additions & 29 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ name: Tests
44
on:
55
issue_comment:
66
merge_group:
7-
pull_request_review_comment:
8-
pull_request_review:
9-
pull_request_target:
107
pull_request:
8+
pull_request_target:
119
push:
1210
workflow_dispatch:
1311

@@ -35,8 +33,10 @@ jobs:
3533
sparse-checkout: action.yml
3634

3735
- name: PR data
38-
id: pr-data
36+
id: pr
3937
uses: ./
4038

4139
- name: Echo data
42-
run: echo Number "${{ steps.pr-data.outputs.number }}" from "${{ github.event_name }} event."
40+
run: |
41+
echo Number "${{ steps.pr.outputs.number }}" from "${{ github.event_name }} event."
42+
echo Branch "${{ steps.pr.outputs.branch }}" from "${{ github.event_name }} event."

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ jobs:
3030
runs-on: ubuntu-latest
3131

3232
permissions:
33-
contents: read # Required to checkout repository.
3433
pull-requests: read # Required to get PR data.
3534

3635
steps:
37-
- uses: actions/checkout@v4
3836
- id: pr
3937
uses: op5dev/current-pr@v1
40-
- run: echo "PR number is ${{ steps.pr.outputs.number }}"
38+
- run: |
39+
echo "PR number ${{ steps.pr.outputs.number }}"
40+
echo "PR branch ${{ steps.pr.outputs.branch }}"
4141
```
4242
4343
</br>
@@ -46,20 +46,18 @@ jobs:
4646
4747
### Inputs
4848
49-
| Required | Name | Description |
50-
| -------- | ------- | ----------------------------------------------------------- |
51-
| No | `token` | Specify a GitHub token.</br>Default: `${{ github.token }}`. |
49+
| Name | Description |
50+
| ------- | -------------------------------------------------------------------------- |
51+
| `token` | Specify a GitHub token (not required).</br>Default: `${{ github.token }}`. |
5252

5353
</br>
5454

5555
### Outputs
5656

57-
| Name | Description |
58-
| ------------ | --------------------------------- |
59-
| ~~`body`~~ | ~~The body of the current PR.~~ |
60-
| ~~`branch`~~ | ~~The branch of the current PR.~~ |
61-
| `number` | The number of the current PR. |
62-
| ~~`title`~~ | ~~The title of the current PR.~~ |
57+
| Name | Description |
58+
| -------- | ------------------ |
59+
| `branch` | Current PR branch. |
60+
| `number` | Current PR number. |
6361

6462
</br>
6563

@@ -86,7 +84,6 @@ View [all notable changes](https://github.com/op5dev/current-pr/releases "Releas
8684

8785
### To-Do
8886

89-
- Output parameters like `body`, `branch`, and `title` will be added in upcoming releases.
9087
- Workflow event triggers like `workflow_dispatch`, and `workflow_run` (fork) will be added in upcoming releases.
9188

9289
</br>

action.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,20 @@ runs:
2525
# Get the PR number by parsing the ref name.
2626
number=$(echo "${GITHUB_REF_NAME}" | sed -n 's/.*pr-\([0-9]*\)-.*/\1/p')
2727
else
28-
# Get the PR number from the event payload or fallback on 0.
28+
# Fallback on 0 if the PR number is not found.
2929
number=${{ github.event.number || github.event.issue.number || 0 }}
3030
fi
31+
branch=${{ github.ref_name || github.head_ref || github.ref || '' }}
32+
echo "branch=$branch" >> "$GITHUB_OUTPUT"
3133
echo "number=$number" >> "$GITHUB_OUTPUT"
3234
3335
outputs:
34-
# body:
35-
# description: "The body of the current PR."
36-
# value: ${{ steps.data.outputs.body }}
37-
# branch:
38-
# description: "The branch of the current PR."
39-
# value: ${{ steps.data.outputs.branch }}
36+
branch:
37+
description: "Current PR branch."
38+
value: ${{ steps.data.outputs.branch }}
4039
number:
41-
description: "The number of the current PR."
40+
description: "Current PR number."
4241
value: ${{ steps.data.outputs.number }}
43-
# title:
44-
# description: "The title of the current PR."
45-
# value: ${{ steps.data.outputs.title }}
4642

4743
inputs:
4844
token:

0 commit comments

Comments
 (0)