@@ -47,32 +47,57 @@ jobs:
4747 'langchain-python-sdk-pr-',
4848 'llamaindex-python-sdk-pr-',
4949 ];
50- const prList = context.payload.check_suite.pull_requests;
51- if (!prList || prList.length === 0) {
52- core.info('No PR found for this check suite. Skipping.');
53- core.setOutput('failure_detected', 'false');
54- return;
55- }
56- const pr_number = prList[0].number;
57- core.setOutput('pr_number', pr_number.toString());
58- const { owner, repo } = context.repo;
59- const sha = context.payload.check_suite.head_sha;
60- const { data: checks } = await github.rest.checks.listForRef({ owner, repo, ref: sha, per_page: 100 });
50+ let pr_number = undefined;
51+ const { owner, repo } = context.repo;
52+ const sha = context.payload.check_suite.head_sha;
53+ if (context.payload.check_suite && context.payload.check_suite.pull_requests && context.payload.check_suite.pull_requests.length > 0) {
54+ pr_number = context.payload.check_suite.pull_requests[0].number;
55+ }
56+ // Fallback: paginate through all open PRs to find matching head SHA
57+ if (!pr_number) {
58+ let page = 1;
59+ let found = false;
60+ while (!found) {
61+ const { data: prs } = await github.rest.pulls.list({
62+ owner,
63+ repo,
64+ state: 'open',
65+ per_page: 100,
66+ page
67+ });
68+ if (!prs || prs.length === 0) {
69+ break;
70+ }
71+ const match = prs.find(pr => pr.head && pr.head.sha === sha);
72+ if (match) {
73+ pr_number = match.number;
74+ found = true;
75+ } else {
76+ page++;
77+ }
78+ }
79+ }
80+ if (!pr_number) {
81+ core.info('No PR found for this check suite or commit. Skipping.');
82+ core.setOutput('failure_detected', 'false');
83+ return;
84+ }
85+ core.setOutput('pr_number', pr_number.toString());
86+ const { data: checks } = await github.rest.checks.listForRef({ owner, repo, ref: sha, per_page: 100 });
6187 const failed = checks.check_runs.filter(
62- c =>
88+ c =>
6389 prefixes.some(prefix => c.name.startsWith(prefix)) &&
6490 c.status === 'completed' &&
6591 c.conclusion === 'failure'
6692 );
6793 if (failed.length === 0) {
68- core.info('No failed Cloud Build checks detected.');
69- core.setOutput('failure_detected', 'false');
70- return;
94+ core.info('No failed Cloud Build checks detected.');
95+ core.setOutput('failure_detected', 'false');
96+ return;
7197 }
7298 core.info(`Detected ${failed.length} failed build(s).`);
7399 core.setOutput('failure_detected', 'true');
74100 core.setOutput('failed_checks', JSON.stringify(failed.map(f => ({ name: f.name, id: f.id, html_url: f.html_url, details_url: f.details_url, external_id: f.external_id || '' }))));
75-
76101
77102 process-failed-builds :
78103 needs : detect-build-failure
0 commit comments