Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2021-02-04 17:37:47 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2021-02-16 17:12:54 +0300
commit6db5e7958ab56ede3bb88522a1c6fb0b47ea77ec (patch)
treebcab6a6d665e39f152193202f5fff57482062232 /tools
parentf6f9af6a595ecae44b1e2854df719d21a6e29f41 (diff)
tools: add GitHub Action linter for pr-url
PR-URL: https://github.com/nodejs/node/pull/37221 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/lint-pr-url.mjs37
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/lint-pr-url.mjs b/tools/lint-pr-url.mjs
new file mode 100755
index 00000000000..3b491d26e38
--- /dev/null
+++ b/tools/lint-pr-url.mjs
@@ -0,0 +1,37 @@
+#!/usr/bin/env node
+
+// Usage:
+// git diff upstream/master...HEAD -G"pr-url:" -- "*.md" | \
+// ./tools/lint-pr-url.mjs <expected-pr-url>
+
+import process from 'node:process';
+import readline from 'node:readline';
+
+const [, , expectedPrUrl] = process.argv;
+
+const fileDelimiter = /^\+\+\+ b\/(.+\.md)$/;
+const changeDelimiter = /^@@ -\d+,\d+ \+(\d+),\d+ @@/;
+const prUrlDefinition = /^\+\s+pr-url: (.+)$/;
+
+const validatePrUrl = (url) => url == null || url === expectedPrUrl;
+
+let currentFile;
+let currentLine;
+
+const diff = readline.createInterface({ input: process.stdin });
+for await (const line of diff) {
+ if (fileDelimiter.test(line)) {
+ currentFile = line.match(fileDelimiter)[1];
+ console.log(`Parsing changes in ${currentFile}.`);
+ } else if (changeDelimiter.test(line)) {
+ currentLine = Number(line.match(changeDelimiter)[1]);
+ } else if (!validatePrUrl(line.match(prUrlDefinition)?.[1])) {
+ console.warn(
+ `::warning file=${currentFile},line=${currentLine++},col=${line.length}` +
+ '::pr-url doesn\'t match the actual PR URL.'
+ );
+ } else if (line[0] !== '-') {
+ // Increment line counter if line is not being deleted.
+ currentLine++;
+ }
+}