diff options
author | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-02-04 17:37:47 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2021-05-01 13:25:07 +0300 |
commit | 981659c7b916612c441b54c1bf1d3789ff00bd46 (patch) | |
tree | da8e92d112ad685aba3061054b54a0bfac4c5ebe /tools | |
parent | b2ee1afb2ee94b7ab3d6664308a829966dc6d045 (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-x | tools/lint-pr-url.mjs | 37 |
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++; + } +} |