Skip to content

Commit 3f19562

Browse files
authored
fix: Don’t fail on issues without linked PRs (#473)
This PR fixes the error— > Unhandled error: TypeError: Cannot use 'in' operator to search for 'source' in undefined —which has caused “Test” workflow run failures (e.g. https://github.com/github-community-projects/continuous-ai-for-accessibility-scanner/actions/runs/17551616985). This PR does 3 things: 1. Removes the use of `in` by replacing it with [optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining). This moots the error above. 2. Adds support for multiple timeline item nodes, in case other timeline items are added _before_ the scanner action assigns an issue to Copilot (i.e. when Copilot coding agent’s PR isn’t the first item). 3. Logs when a linked PR is not found for an issue, to help with future debugging.
2 parents 6e121fd + 0d5ca84 commit 3f19562

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
2626
strategy:
2727
matrix:
28-
site: [ "sites/site-with-errors" ]
28+
site: ["sites/site-with-errors"]
2929
steps:
3030
- name: Checkout
3131
uses: actions/checkout@v5
@@ -103,14 +103,12 @@ jobs:
103103
}`;
104104
const variables = { owner, repo, issueNumber: parseInt(issueNumber, 10) }
105105
const result = await github.graphql(query, variables)
106-
let pullRequest;
107-
if ('source' in result.repository?.issue?.timelineItems.nodes[0]) {
108-
pullRequest = result.repository?.issue?.timelineItems.nodes[0].source;
109-
} else if ('subject' in result.repository?.issue?.timelineItems.nodes[0]) {
110-
pullRequest = result.repository?.issue?.timelineItems.nodes[0].subject;
111-
}
112-
if (pullRequest) {
113-
finding.pullRequestUrl = pullRequest.url;
106+
const timelineNodes = result?.repository?.issue?.timelineItems?.nodes || [];
107+
const pullRequestNode = timelineNodes.find(n => n?.source?.url || n?.subject?.url);
108+
if (pullRequestNode) {
109+
finding.pullRequestUrl = pullRequestNode.source?.url || pullRequestNode.subject?.url;
110+
} else {
111+
core.info(`No pull request found for issue: ${finding.issueUrl}`);
114112
}
115113
}
116114
fs.writeFileSync(process.env.FINDINGS_PATH, JSON.stringify(findings));

0 commit comments

Comments
 (0)