Skip to content

Commit

Permalink
[ARMAutoSignoff] Fix usage of github.paginate() (#32645)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeharder authored Feb 16, 2025
1 parent e26b89b commit 83a2ab4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function extractInputs(github, context, core) {
},
);

const artifactNames = artifacts.artifacts.map((a) => a.name);
const artifactNames = artifacts.map((a) => a.name);

core.info(`artifactNames: ${JSON.stringify(artifactNames)}`);

Expand Down
9 changes: 7 additions & 2 deletions .github/test/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { vi } from "vitest";
// Partial mock of `github` parameter passed into github-script actions
export function createMockGithub() {
return {
// Simulate assuming test data fits in single page
paginate: async (func, params) => (await func(params)).data,
paginate: async (func, params) => {
// Assume all test data fits in single page
const data = (await func(params)).data;

// Simulate normalization performed by real impl
return data.artifacts || data.workflow_runs || data.check_runs || data;
},
rest: {
actions: {
listWorkflowRunArtifacts: vi
Expand Down
53 changes: 25 additions & 28 deletions .github/workflows/src/arm-auto-signoff-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,12 @@ export async function getLabelActionImpl({
);

core.info("Workflow Runs:");
workflowRuns.workflow_runs.forEach((wf) => {
workflowRuns.forEach((wf) => {
core.info(`- ${wf.name}: ${wf.conclusion || wf.status}`);
});

const wfName = "ARM Incremental Typespec (Preview)";
const incrementalTspRuns = workflowRuns.workflow_runs.filter(
(wf) => wf.name == wfName,
);
const incrementalTspRuns = workflowRuns.filter((wf) => wf.name == wfName);

if (incrementalTspRuns.length == 0) {
core.info(
Expand All @@ -104,14 +102,16 @@ export async function getLabelActionImpl({
return labelActions[LabelAction.Remove];
}

const artifactNames = (
await github.paginate(github.rest.actions.listWorkflowRunArtifacts, {
const artifacts = await github.paginate(
github.rest.actions.listWorkflowRunArtifacts,
{
owner,
repo,
run_id: run.id,
per_page: PER_PAGE_MAX,
})
).artifacts.map((a) => a.name);
},
);
const artifactNames = artifacts.map((a) => a.name);

core.info(`artifactNames: ${JSON.stringify(artifactNames)}`);

Expand All @@ -128,37 +128,34 @@ export async function getLabelActionImpl({
}

// TODO: Try to extract labels from context (when available) to avoid unnecessary API call
const labels = (
await github.paginate(github.rest.issues.listLabelsOnIssue, {
owner: owner,
repo: repo,
issue_number: issue_number,
per_page: PER_PAGE_MAX,
})
).map((label) => label.name);
const labels = await github.paginate(github.rest.issues.listLabelsOnIssue, {
owner: owner,
repo: repo,
issue_number: issue_number,
per_page: PER_PAGE_MAX,
});
const labelNames = labels.map((label) => label.name);

core.info(`Labels: ${labels}`);

// TODO: Also require label "ARMBestPracticesAcknowledgement"
const allLabelsMatch =
labels.includes("ARMReview") &&
!labels.includes("NotReadyForARMReview") &&
(!labels.includes("SuppressionReviewRequired") ||
labels.includes("Approved-Suppression"));
labelNames.includes("ARMReview") &&
!labelNames.includes("NotReadyForARMReview") &&
(!labelNames.includes("SuppressionReviewRequired") ||
labelNames.includes("Approved-Suppression"));

if (!allLabelsMatch) {
core.info("Labels do not meet requirement for auto-signoff");
return labelActions[LabelAction.Remove];
}

const checkRuns = (
await github.paginate(github.rest.checks.listForRef, {
owner: owner,
repo: repo,
ref: head_sha,
per_page: PER_PAGE_MAX,
})
).check_runs;
const checkRuns = await github.paginate(github.rest.checks.listForRef, {
owner: owner,
repo: repo,
ref: head_sha,
per_page: PER_PAGE_MAX,
});

const swaggerLintDiffs = checkRuns.filter(
(run) => run.name === "Swagger LintDiff",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/src/update-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function updateLabelsImpl({
},
);

artifactNames = artifacts.artifacts.map((a) => a.name);
artifactNames = artifacts.map((a) => a.name);
} else {
// TODO: List all artifacts of all workflows associated with issue_number
throw new Error("Required input 'run_id' not found in env or context");
Expand Down

0 comments on commit 83a2ab4

Please sign in to comment.