Skip to content

Commit b3ff4f8

Browse files
committed
[suggestion-bot] Move PR extraction to Caller
1 parent 29176fd commit b3ff4f8

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

.github/workflows/ai-triage.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: AI Triage (Caller)
22

33
on:
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

1414
jobs:
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 }}

.github/workflows/ci_exp.yml

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
name: CI Experiment
1+
name: CI Experiment (Fail)
22

33
on:
4-
pull_request:
54
push:
6-
branches: [master, main]
5+
paths:
6+
- 'ci_exp/**'
7+
pull_request:
78

89
jobs:
910
test:
1011
runs-on: ubuntu-latest
1112
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v4
14-
15-
- name: Save PR Number
16-
if: always()
17-
run: |
18-
echo "${{ github.event.number }}" > pr_number.txt
19-
20-
- name: Upload PR Number
21-
if: always()
22-
uses: actions/upload-artifact@v4
23-
with:
24-
name: failure-evidence
25-
path: pr_number.txt
26-
27-
- name: Run Script
28-
run: |
29-
echo "Running critical tests..."
30-
python ci_exp/test_file.py
13+
- uses: actions/checkout@v4
14+
- name: Run Broken Script
15+
run: python ci_exp/test_file.py

0 commit comments

Comments
 (0)