MCPcopy Create free account
hub / github.com/NomicFoundation/hardhat / validatePullRequest

Function validatePullRequest

scripts/validate-pull-request-docs.ts:100–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98}
99
100async function validatePullRequest() {
101 if (isReleasePR()) {
102 console.log("Ignore docs check for release PR.");
103 return;
104 }
105
106 if (hasNoDocsNeededLabel()) {
107 console.log(`The PR is labeled as '${SKIP_LABEL}'`);
108 return;
109 }
110
111 const bodyUrls = extractDocsUrlsFromPRBody();
112 const changesetUrls = await collectDocsUrlsFromChangesets();
113 const changesetUrlSet = new Set(changesetUrls.map(normalizeDocsUrl));
114
115 const unmatchedBodyUrls = bodyUrls.filter(
116 (url) => !changesetUrlSet.has(normalizeDocsUrl(url)),
117 );
118
119 if (unmatchedBodyUrls.length > 0) {
120 throw new Error(
121 "Found hardhat-website PR link(s) in the PR body that are not referenced in any changeset:\n" +
122 unmatchedBodyUrls.map((u) => ` - ${u}`).join("\n") +
123 "\n\n" +
124 "Add a `# docs:` comment for each in a changeset frontmatter:\n\n" +
125 " ---\n" +
126 " # docs: https://github.com/NomicFoundation/hardhat-website/pull/<number>\n" +
127 ' "package-name": patch\n' +
128 " ---",
129 );
130 }
131
132 if (changesetUrls.length > 0) {
133 console.log("Docs link found in changeset frontmatter");
134 return;
135 }
136
137 if (hasIssueLinkInPRBody()) {
138 console.log("Issue link to docs found in PR body");
139 return;
140 }
141
142 throw new Error(
143 "No links to docs found. Either:\n" +
144 `- Add the '${SKIP_LABEL}' label\n` +
145 "- Add a `# docs:` comment in your changeset frontmatter:\n\n" +
146 " ---\n" +
147 " # docs: https://github.com/NomicFoundation/hardhat-website/pull/<number>\n" +
148 ' "package-name": patch\n' +
149 " ---\n\n" +
150 "- Or link to a hardhat-website issue in the PR body",
151 );
152}
153
154await validatePullRequest();

Callers 1

Calls 7

hasNoDocsNeededLabelFunction · 0.85
normalizeDocsUrlFunction · 0.85
hasIssueLinkInPRBodyFunction · 0.85
filterMethod · 0.80
isReleasePRFunction · 0.70

Tested by

no test coverage detected