MCPcopy Create free account
hub / github.com/alibaba/open-code-review / runLinksCheck

Function runLinksCheck

scripts/github-actions/check-plugin-contract.js:883–946  ·  view source on GitHub ↗
({
  repoRoot = process.cwd(),
  minLinks = MIN_EXPECTED_LINKS,
  minFiles = MIN_EXPECTED_LINK_FILES,
  maxScanBytes = MAX_SCAN_BYTES,
} = {})

Source from the content-addressed store, hash-verified

881
882// BLOCKING. Returns a process exit code (0 ok, 1 on a broken link).
883function runLinksCheck({
884 repoRoot = process.cwd(),
885 minLinks = MIN_EXPECTED_LINKS,
886 minFiles = MIN_EXPECTED_LINK_FILES,
887 maxScanBytes = MAX_SCAN_BYTES,
888} = {}) {
889 const files = walkTextFiles(repoRoot);
890 const links = [];
891 const skipped = [];
892 for (const file of files) {
893 const content = readFileOrNull(path.join(repoRoot, file), { maxBytes: maxScanBytes });
894 if (content === null) {
895 // A documentation file that could not be read is a hole in the corpus,
896 // not a pass. Reporting it keeps this consistent with the fail-closed
897 // corpus floor below, which can only catch a scan that broke wholesale
898 // and would miss individual documents being skipped in silence.
899 if (DOC_EXTENSIONS.test(file)) skipped.push(file);
900 continue;
901 }
902 // Cheap prefilter: most files mention the slug nowhere.
903 if (!content.includes(REPO_SLUG)) continue;
904 for (const l of extractRepoLinks(content)) links.push({ ...l, file });
905 }
906
907 for (const file of skipped) {
908 emitWarning(
909 file,
910 `Skipped by the link scan (unreadable, binary, or larger than ` +
911 `${maxScanBytes} bytes), so its in-repo links were NOT verified.`
912 );
913 }
914
915 const fileCount = new Set(links.map((l) => l.file)).size;
916 const floor = checkCorpusFloor(links.length, fileCount, minLinks, minFiles);
917 if (floor) {
918 emitError(null, `In-repo link check failed: ${floor}`);
919 return 1;
920 }
921
922 const { errors, warnings } = validateRepoLinks(links, (p) => probeKind(repoRoot, p));
923 for (const err of errors) emitError(err.file, err.message, err.line);
924 for (const warn of warnings) emitWarning(warn.file, warn.message, warn.line);
925
926 if (errors.length === 0) {
927 const unique = new Set(links.map((l) => l.repoPath)).size;
928 console.log(
929 `In-repo link check passed: ${links.length} link(s) across ` +
930 `${fileCount} file(s) resolve to ` +
931 `${unique} existing path(s)` +
932 (warnings.length || skipped.length
933 ? `, with ${warnings.length} blob/tree kind warning(s) and ` +
934 `${skipped.length} unscanned doc(s).`
935 : ".")
936 );
937 return 0;
938 }
939 emitError(
940 null,

Calls 8

walkTextFilesFunction · 0.85
readFileOrNullFunction · 0.85
extractRepoLinksFunction · 0.85
checkCorpusFloorFunction · 0.85
validateRepoLinksFunction · 0.85
probeKindFunction · 0.85
emitWarningFunction · 0.70
emitErrorFunction · 0.70