From 573639e0919abf538ddae6d1df77a8270445c8d6 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 24 Sep 2024 10:42:38 -0400 Subject: [PATCH] Try even harder --- .../workflows/github-actions-comment-test.yml | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/github-actions-comment-test.yml b/.github/workflows/github-actions-comment-test.yml index dc5eaa0901..e1da1a1ec9 100644 --- a/.github/workflows/github-actions-comment-test.yml +++ b/.github/workflows/github-actions-comment-test.yml @@ -13,17 +13,29 @@ jobs: uses: actions/checkout@v3 - name: Test uses: actions/github-script@0.3.0 + id: get_issue_number with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const core = require('@actions/core') - const prNumber = context.payload.number; - core.exportVariable('PULL_NUMBER', prNumber); + script: | + if (context.issue.number) { + // Return issue number if present + return context.issue.number; + } else { + // Otherwise return issue number from commit + return ( + await github.rest.repos.listPullRequestsAssociatedWithCommit({ + commit_sha: context.sha, + owner: context.repo.owner, + repo: context.repo.repo, + }) + ).data[0].number; + } + result-encoding: string + - name: Issue number + run: echo '${{steps.get_issue_number.outputs.result}}' - name: Leave PR comment env: - PR_NUMBER: ${{ PULL_NUMBER }} + PR_NUMBER: ${{ steps.get_issue_number.outputs.result }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | curl -H "Authorization: token ${GITHUB_TOKEN}" \ -X POST \