()
| 98 | } |
| 99 | |
| 100 | async 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 | |
| 154 | await validatePullRequest(); |
no test coverage detected