From 2b95f4243a6dc1bcedb32e9b2ca14006a16caebb Mon Sep 17 00:00:00 2001 From: Joris Roovers Date: Fri, 23 Jun 2023 12:39:07 +0200 Subject: [PATCH] GHA: Notify - extract PR number when merging on main (#511) 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. --- .github/workflows/ci.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2941a61..abd2b73e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/checkout@v3.3.0 + 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: | @@ -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