Copilot commented on code in PR #1407:
URL: https://github.com/apache/daffodil-vscode/pull/1407#discussion_r2325616019
##########
.github/workflows/CI.yml:
##########
@@ -58,9 +72,60 @@ jobs:
############################################################
# Setup
############################################################
+ - name: Resolve PR metadata
+ id: meta
+ uses: actions/github-script@v7
+ with:
+ script: |
+ // Set outputs for manual dispatch, PR events, and defaults for
other events.
+ if (context.event_name === 'workflow_dispatch') {
+ const prNumber = Number(core.getInput('pr'));
Review Comment:
The `core.getInput('pr')` call will fail because the input parameter is not
available in this context. The workflow input should be accessed via
`context.payload.inputs.pr` for workflow_dispatch events.
```suggestion
const prNumber = Number(context.payload.inputs.pr);
```
##########
.github/workflows/CI.yml:
##########
@@ -109,9 +179,60 @@ jobs:
############################################################
# Setup
############################################################
+ - name: Resolve PR metadata
+ id: meta
+ uses: actions/github-script@v7
+ with:
+ script: |
+ // Set outputs for manual dispatch, PR events, and defaults for
other events.
+ if (context.event_name === 'workflow_dispatch') {
+ const prNumber = Number(core.getInput('pr'));
+ if (Number.isNaN(prNumber)) {
+ 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.info(`Verifying PR #${prNumber} from
${pr.head.repo.full_name}:${pr.head.ref}`);
+ return;
+ }
- - name: Check out Repository
+ if (context.event_name === 'pull_request') {
+ // When triggered by pull_request we can resolve the PR from
context.issue.number
+ 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.info(`Resolved PR #${prNumber} from
${pr.head.repo.full_name}:${pr.head.ref}`);
+ return;
+ }
+
+ // Fallback for push and other events: use repository and ref
defaults
+ core.setOutput('head_repo',
`${context.repo.owner}/${context.repo.repo}`);
+ core.setOutput('head_ref', process.env.GITHUB_REF || context.ref
|| '');
+ core.info(`Not a workflow_dispatch or pull_request; using
${context.repo.owner}/${context.repo.repo}:${process.env.GITHUB_REF ||
context.ref}`);
+
Review Comment:
The PR metadata resolution logic is duplicated between the lint-and-format
and test jobs. This should be extracted into a reusable composite action or a
shared job to reduce duplication and improve maintainability.
```suggestion
uses: ./.github/actions/resolve-pr-metadata
with:
pr: ${{ github.event.inputs.pr }}
```
--
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]