@@ -35,12 +35,46 @@ jobs:
3535 echo "HAS_DIFF=false" >> $GITHUB_OUTPUT
3636 fi
3737
38+ - name : Get PR number from workflow run
39+ id : pr-number
40+ uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
41+ with :
42+ script : |
43+ // Try to get PR number from artifact first, otherwise from the workflow run
44+ let prNumber = ${{ steps.extract.outputs.PR_NUMBER || 'null' }};
45+
46+ if (!prNumber) {
47+ // Get PR number from the workflow run event
48+ const headRepo = context.payload.workflow_run.head_repository.owner.login;
49+ const headBranch = context.payload.workflow_run.head_branch;
50+
51+ console.log(`Looking for PR with head: ${headRepo}:${headBranch}`);
52+
53+ const { data: pullRequests } = await github.rest.pulls.list({
54+ owner: context.repo.owner,
55+ repo: context.repo.repo,
56+ state: 'open',
57+ head: `${headRepo}:${headBranch}`,
58+ });
59+
60+ if (pullRequests.length > 0) {
61+ prNumber = pullRequests[0].number;
62+ console.log(`Found PR #${prNumber} for branch ${headBranch}`);
63+ } else {
64+ console.log('No open PR found for this workflow run');
65+ console.log('This might be a push to a non-PR branch, skipping comment workflow');
66+ return;
67+ }
68+ }
69+
70+ core.setOutput('number', prNumber);
71+
3872 - name : Delete previous pre-commit failure comments
39- if : steps.extract .outputs.HAS_DIFF == 'true'
73+ if : steps.pr-number .outputs.number
4074 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
4175 with :
4276 script : |
43- const prNumber = ${{ steps.extract .outputs.PR_NUMBER }};
77+ const prNumber = ${{ steps.pr-number .outputs.number }};
4478
4579 // Get all comments on the PR
4680 const { data: comments } = await github.rest.issues.listComments({
81115 with :
82116 script : |
83117 const fs = require('fs');
84- const prNumber = ${{ steps.extract .outputs.PR_NUMBER }};
118+ const prNumber = ${{ steps.pr-number .outputs.number }};
85119 const diff = fs.readFileSync('diff.txt', 'utf8');
86120
87121 const body = `## ⚠️ Pre-commit Hook Failures
0 commit comments