Skip to content

Commit 23bd4e2

Browse files
better logging for link check
1 parent c03c54c commit 23bd4e2

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

check.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ onExit();
66
async function checkList(list) {
77
return await Promise.all(
88
// for each redirect
9-
list.map(async ({ to }) => {
9+
list.map(async ({ to, file, index }) => {
1010
try {
1111
// do simple request to target url
1212
const response = await fetch(to);
@@ -19,10 +19,12 @@ async function checkList(list) {
1919
)
2020
throw Error(response.status);
2121
} catch (error) {
22-
addError(`"to: ${to}" may be a broken link\n(${error})`);
22+
addError(
23+
`${file} entry ${index} "to: ${to}" may be a broken link\n (${error})`
24+
);
2325
}
2426
})
2527
);
2628
}
2729

28-
await checkList(getList());
30+
await checkList(getList(true));

core.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { parse } from "yaml";
77
export const verbose = !!process.env.RUNNER_DEBUG;
88

99
// get full list of redirects
10-
export function getList() {
10+
export function getList(meta) {
1111
// get yaml files that match glob pattern
1212
const files = globSync("*.y?(a)ml", { cwd: __dirname });
1313

@@ -63,12 +63,16 @@ export function getList() {
6363
// normalize "from" field. lower case, remove leading slashes.
6464
entry.from = entry.from.toLowerCase().replace(/^(\/+)/, "");
6565

66+
// record meta for logging
67+
entry.file = file;
68+
entry.index = index;
69+
6670
// add to combined list
6771
list.push(entry);
6872

69-
// add to duplicate list. record source file and entry number for logging.
73+
// add to duplicate list
7074
duplicates[entry.from] ??= [];
71-
duplicates[entry.from].push({ ...entry, file, index });
75+
duplicates[entry.from].push(entry);
7276
}
7377
}
7478

@@ -87,6 +91,13 @@ export function getList() {
8791
addError(`"from: ${from}" appears ${count} time(s): ${duplicates}`);
8892
}
8993

94+
// if meta not requested, clean up
95+
if (!meta)
96+
list.forEach((entry) => {
97+
delete entry.file;
98+
delete entry.index;
99+
});
100+
90101
return list;
91102
}
92103

0 commit comments

Comments
 (0)