Skip to content

Commit 9983357

Browse files
committed
Add support for retrieving PR number from GitHub API in CI workflow for forks
1 parent 9b12637 commit 9983357

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

.github/workflows/ci-post-comment.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,22 @@ jobs:
1616
run-id: ${{ github.event.workflow_run.id }}
1717
github-token: ${{ secrets.GITHUB_TOKEN }}
1818

19+
- name: Get PR Number from GitHub API (for forks)
20+
id: get_pr_number
21+
run: |
22+
if [[ "${{ github.event.workflow_run.head_repository.fork }}" == "true" ]]; then
23+
echo "This is a forked repository."
24+
pr_number=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
25+
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.event.workflow_run.head_repository.owner.login }}:${{ github.event.workflow_run.head_branch }}" \
26+
| jq '.[0].number')
27+
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
28+
else
29+
echo "pr_number=${{ github.event.workflow_run.pull_requests[0].number }}" >> $GITHUB_OUTPUT
30+
fi
31+
1932
- name: Add Coverage PR Comment
2033
uses: marocchino/sticky-pull-request-comment@v2
2134
with:
2235
recreate: true
2336
path: code-coverage-results.md
24-
number: ${{ github.event.workflow_run.pull_requests[0].number }}
37+
number: ${{ steps.get_pr_number.outputs.pr_number }}

0 commit comments

Comments
 (0)