Copilot commented on code in PR #1407:
URL: https://github.com/apache/daffodil-vscode/pull/1407#discussion_r2325685536
##########
.github/workflows/CI.yml:
##########
@@ -109,9 +182,63 @@ jobs:
############################################################
# Setup
############################################################
+ - name: Resolve PR metadata
+ id: meta
+ uses: actions/github-script@v7
+ with:
+ script: |
+ // Handle workflow_dispatch, pull_request, and fallback
(push/other)
+ if (context.eventName === 'workflow_dispatch') {
Review Comment:
The PR metadata resolution logic is duplicated between lines 79-123 and
lines 189-232. This duplicated code should be extracted into a reusable action
or moved to a shared step to improve maintainability.
##########
.github/workflows/CI.yml:
##########
@@ -58,9 +72,63 @@ jobs:
############################################################
# Setup
############################################################
+ - name: Resolve PR metadata
+ id: meta
+ uses: actions/github-script@v7
+ with:
+ script: |
+ // Handle workflow_dispatch, pull_request, and fallback
(push/other)
+ if (context.eventName === 'workflow_dispatch') {
+ const raw = (context.payload.inputs &&
context.payload.inputs.pr) || '';
+ const prNumber = Number(raw);
+ if (!Number.isFinite(prNumber) || prNumber <= 0) {
+ core.setFailed("Missing or invalid 'pr' input for
workflow_dispatch.");
+ return;
+ }
+ const { data: pr } = await github.rest.pulls.get({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: prNumber
+ });
+ if (pr.state !== 'open') {
+ core.setFailed(`PR #${prNumber} is not open
(state=${pr.state}).`);
+ return;
+ }
+ core.setOutput('head_repo', pr.head.repo.full_name);
+ core.setOutput('head_ref', pr.head.ref);
+ core.setOutput('head_sha', pr.head.sha);
+ core.info(`Verifying PR #${prNumber} from
${pr.head.repo.full_name}:${pr.head.ref} @ ${pr.head.sha}`);
+ return;
+ }
- - name: Check out Repository
+ if (context.eventName === 'pull_request') {
+ const prNumber = context.issue.number;
+ const { data: pr } = await github.rest.pulls.get({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: prNumber
+ });
+ core.setOutput('head_repo', pr.head.repo.full_name);
+ core.setOutput('head_ref', pr.head.ref);
+ core.setOutput('head_sha', pr.head.sha);
+ core.info(`Resolved PR #${prNumber} from
${pr.head.repo.full_name}:${pr.head.ref} @ ${pr.head.sha}`);
+ return;
+ }
+
+ // Fallback for push/other events
+ core.setOutput('head_repo',
`${context.repo.owner}/${context.repo.repo}`);
+ core.setOutput('head_ref', process.env.GITHUB_REF || context.ref
|| '');
+ core.setOutput('head_sha', context.sha);
+ core.info(`Non-PR event; using
${context.repo.owner}/${context.repo.repo}:${process.env.GITHUB_REF ||
context.ref} @ ${context.sha}`);
+
Review Comment:
The PR metadata resolution logic is duplicated between lines 79-123 and
lines 189-232. This duplicated code should be extracted into a reusable action
or moved to a shared step to improve maintainability.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]