Skip to content

Commit e163f15

Browse files
authored
try to apply suggestions
1 parent 1946ef7 commit e163f15

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

.github/actions/get_pr_number/action.yml

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,48 @@ description: Get the PR number without relying on the pull_request* event trigge
55
runs:
66
using: composite
77
steps:
8-
# The steps below are executed only when testing in a PR.
9-
- name: Get PR info
8+
- name: Get PR info (non-main branch)
109
if: ${{ github.ref_name != 'main' }}
1110
uses: nv-gha-runners/get-pr-info@main
1211
id: get-pr-info
13-
14-
- name: Extract PR number from info
12+
13+
- name: Extract PR number (non-main branch)
1514
if: ${{ github.ref_name != 'main' }}
1615
shell: bash --noprofile --norc -xeuo pipefail {0}
1716
run: |
17+
trap 'echo "Error at line $LINENO"; exit 1' ERR
1818
PR_NUMBER="${{ fromJSON(steps.get-pr-info.outputs.pr-info).number }}"
19-
if [[ "$PR_NUMBER" == "" ]]; then
20-
echo "cannot extract PR number"
19+
if [[ -z "$PR_NUMBER" ]]; then
20+
echo "Cannot extract PR number for ref: ${{ github.ref_name }}"
2121
exit 1
22-
else
23-
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
2422
fi
25-
26-
# The steps below are executed only when building on main.
27-
- name: Get PR data
23+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
24+
25+
- name: Get PR data (main branch)
2826
if: ${{ github.ref_name == 'main' }}
2927
uses: actions/github-script@v7
3028
id: get-pr-data
3129
with:
3230
script: |
33-
return (
34-
await github.rest.repos.listPullRequestsAssociatedWithCommit({
35-
commit_sha: context.sha,
36-
owner: context.repo.owner,
37-
repo: context.repo.repo,
38-
})
39-
).data[0];
40-
41-
- name: Extract PR number from data
31+
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
32+
commit_sha: context.sha,
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
});
36+
if (!prs.data.length) {
37+
core.setFailed("No PR associated with this commit on 'main'.");
38+
} else {
39+
return prs.data[0];
40+
}
41+
42+
- name: Extract PR number (main branch)
4243
if: ${{ github.ref_name == 'main' }}
4344
shell: bash --noprofile --norc -xeuo pipefail {0}
4445
run: |
46+
trap 'echo "Error at line $LINENO"; exit 1' ERR
4547
PR_NUMBER="${{ fromJSON(steps.get-pr-data.outputs.result).number }}"
46-
if [[ "$PR_NUMBER" == "" ]]; then
47-
echo "cannot extract PR number"
48+
if [[ -z "$PR_NUMBER" ]]; then
49+
echo "No associated PR found for the commit in 'main'."
4850
exit 1
49-
else
50-
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
5151
fi
52+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV

0 commit comments

Comments
 (0)