Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion review-enrichment/src/analyzers/actions-pin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const FULL_SHA = /^[0-9a-f]{40}$/;
const OFFICIAL = /^(actions|github)\//;
const WORKFLOW_PATH = /^\.github\/workflows\/.+\.ya?ml$/;

function isWorkflowPath(path: string): boolean {
return WORKFLOW_PATH.test(path.replace(/\\/g, "/").toLowerCase());
}

/** Scan one workflow patch's added lines for unpinned third-party `uses:` refs, line-cited via hunk headers. Pure. */
export function scanWorkflowPins(
path: string,
Expand Down Expand Up @@ -46,7 +50,7 @@ export async function scanActionPins(
): Promise<ActionPinFinding[]> {
const findings: ActionPinFinding[] = [];
for (const file of req.files ?? []) {
if (WORKFLOW_PATH.test(file.path) && file.patch) {
if (isWorkflowPath(file.path) && file.patch) {
findings.push(...scanWorkflowPins(file.path, file.patch));
}
}
Expand Down
26 changes: 26 additions & 0 deletions review-enrichment/test/actions-pin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,29 @@ test("scanActionPins scans only changed workflow YAML files with patches", async
},
]);
});

test("scanActionPins matches workflow paths case-insensitively", async () => {
const findings = await scanActionPins({
repoFullName: "o/r",
prNumber: 1,
files: [
{
path: ".github/Workflows/CI.YML",
patch: "@@ -1,0 +5,1 @@\n+ - uses: pnpm/action-setup@v3",
},
{
path: "docs/workflow.yml",
patch: "@@ -1,0 +1,1 @@\n+ - uses: vendor/not-a-workflow@main",
},
],
});

assert.deepEqual(findings, [
{
file: ".github/Workflows/CI.YML",
line: 5,
action: "pnpm/action-setup",
ref: "v3",
},
]);
});
Loading