summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoris Roovers <joris.roovers@gmail.com>2023-06-23 12:39:07 +0200
committerJoris Roovers <joris.roovers@gmail.com>2023-06-23 11:47:09 +0000
commit2b95f4243a6dc1bcedb32e9b2ca14006a16caebb (patch)
tree31e039ceb4a0e02eed319d762890d2e12da1a419
parentde7f8e2e7412be44f731e637d83bc3f51206c93a (diff)
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.
-rw-r--r--.github/workflows/ci.yml16
1 files changed, 15 insertions, 1 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d2941a6..abd2b73 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