Skip to content

Commit

Permalink
GHA: Notify - extract PR number when merging on main (#511)
Browse files Browse the repository at this point in the history
When using github.rest.issues.createComment, context.issue.number
does not work when the notify job is triggered by a push to the 'main'
branch event.

Instead, we manually extract the PR number using the gh CLI.
  • Loading branch information
jorisroovers committed Jun 23, 2023
1 parent de7f8e2 commit 2b95f42
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ jobs:
if: github.ref == 'refs/heads/main'
runs-on: "ubuntu-latest"
steps:
# Checkout code in order to determine PR number
- uses: actions/[email protected]
with:
fetch-depth: 0

- name: Get PR number
run: |
commit_sha=$(git rev-parse HEAD)
pr_number=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/jorisroovers/gitlint/commits/$commit_sha/pulls" | jq -r '.[0].number')
echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/github-script@v6
with:
script: |
Expand All @@ -259,7 +273,7 @@ jobs:
\`\`\`
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
issue_number: process.env.PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
Expand Down

0 comments on commit 2b95f42

Please sign in to comment.