Lint: Report duplicated changelog (#9666)
This commit is contained in:
1 parent
4bcf8a3a36
commit
3e20fc244c
1 file changed
+13
-1
@@ -2,6 +2,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const { outdent } = require("outdent");
|
||||||
|
|
||||||
const CHANGELOG_DIR = "changelog_unreleased";
|
const CHANGELOG_DIR = "changelog_unreleased";
|
||||||
const TEMPLATE_FILE = "TEMPLATE.md";
|
const TEMPLATE_FILE = "TEMPLATE.md";
|
||||||
@@ -61,6 +62,7 @@ const template = fs.readFileSync(
|
|||||||
);
|
);
|
||||||
const [templateComment] = template.match(/<!--[\S\s]*?-->/);
|
const [templateComment] = template.match(/<!--[\S\s]*?-->/);
|
||||||
const [templateAuthorLink] = template.match(authorRegex);
|
const [templateAuthorLink] = template.match(authorRegex);
|
||||||
|
const checkedFiles = new Map();
|
||||||
|
|
||||||
for (const category of CHANGELOG_CATEGORIES) {
|
for (const category of CHANGELOG_CATEGORIES) {
|
||||||
const files = fs.readdirSync(path.join(CHANGELOG_ROOT, category));
|
const files = fs.readdirSync(path.join(CHANGELOG_ROOT, category));
|
||||||
@@ -85,11 +87,21 @@ for (const category of CHANGELOG_CATEGORIES) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const [, prNumber] = match;
|
const [, prNumber] = match;
|
||||||
|
const prLink = `#${prNumber}`;
|
||||||
|
if (checkedFiles.has(prNumber)) {
|
||||||
|
showErrorMessage(
|
||||||
|
outdent`
|
||||||
|
Duplicate files for ${prLink} found.
|
||||||
|
- ${checkedFiles.get(prNumber)}
|
||||||
|
- ${displayPath}
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
checkedFiles.set(prNumber, displayPath);
|
||||||
const content = fs.readFileSync(
|
const content = fs.readFileSync(
|
||||||
path.join(CHANGELOG_DIR, category, prFile),
|
path.join(CHANGELOG_DIR, category, prFile),
|
||||||
"utf8"
|
"utf8"
|
||||||
);
|
);
|
||||||
const prLink = `#${prNumber}`;
|
|
||||||
|
|
||||||
if (!content.includes(prLink)) {
|
if (!content.includes(prLink)) {
|
||||||
showErrorMessage(`[${displayPath}]: PR link "${prLink}" is missing.`);
|
showErrorMessage(`[${displayPath}]: PR link "${prLink}" is missing.`);
|
||||||
|
|||||||
Reference in new issue
Block a user