@@ -2,7 +2,7 @@ name: AI Triage (Caller)
22
33on :
44 workflow_run :
5- workflows : ["CI Experiment"]
5+ workflows : ["CI Experiment (Fail) "]
66 types :
77 - completed
88
@@ -12,28 +12,40 @@ permissions:
1212 contents : read
1313
1414jobs :
15- prepare :
15+ find-pr :
1616 runs-on : ubuntu-latest
1717 if : ${{ github.event.workflow_run.conclusion == 'failure' }}
1818 outputs :
1919 pr_number : ${{ steps.pr.outputs.number }}
2020 steps :
21- - name : Download PR Number Artifact
22- uses : actions/download-artifact@v4
23- with :
24- run-id : ${{ github.event.workflow_run.id }}
25- github-token : ${{ secrets.GITHUB_TOKEN }}
26- name : failure-evidence
27- path : .
28- - id : pr
29- run : echo "number=$(cat pr_number.txt)" >> $GITHUB_OUTPUT
21+ - name : Find PR Number
22+ id : pr
23+ env :
24+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
25+ run : |
26+ PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}"
27+ if [ -n "$PR_NUMBER" ]; then
28+ echo "Found PR #$PR_NUMBER from workflow payload."
29+ echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
30+ exit 0
31+ fi
32+ HEAD_SHA="${{ github.event.workflow_run.head_sha }}"
33+ echo "Payload empty. Searching for PR by Commit SHA ($HEAD_SHA)..."
34+ PR_NUMBER=$(gh pr list --search "$HEAD_SHA" --state open --json number --jq '.[0].number')
35+ if [ -n "$PR_NUMBER" ]; then
36+ echo "Found PR #$PR_NUMBER using Commit SHA."
37+ echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT
38+ exit 0
39+ fi
40+ echo "::warning::No open PR found. This was likely a push to master."
41+ exit 0
3042
3143 call-triage-bot :
32- needs : prepare
33- if : ${{ github.event.workflow_run.conclusion == 'failure ' }}
34- uses : openwisp/openwisp-utils/.github/workflows/reusable-ai-triage.yml@issues/524-ci-failure-bot
44+ needs : find-pr
45+ if : ${{ needs.find-pr.outputs.pr_number != ' ' }}
46+ uses : openwisp/openwisp-utils/.github/workflows/reusable-ai-triage.yml@<YOUR_BRANCH_NAME>
3547 with :
36- pr_number : ${{ needs.prepare .outputs.pr_number }}
48+ pr_number : ${{ needs.find-pr .outputs.pr_number }}
3749 head_sha : ${{ github.event.workflow_run.head_sha }}
3850 head_repo : ${{ github.event.workflow_run.head_repository.full_name }}
3951 run_id : ${{ github.event.workflow_run.id }}
0 commit comments