-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools: add GitHub Action linter for pr-url #37221
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,3 +98,12 @@ jobs: | |
- uses: mszostok/[email protected] | ||
with: | ||
checks: "files,duppatterns" | ||
lint-pr-url: | ||
if: ${{ github.event.pull_request }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 2 | ||
# GH Actions squashes all PR commits, HEAD^ refers to the base branch. | ||
- run: git diff HEAD^ HEAD -G"pr-url:" -- "*.md" | ./tools/lint-pr-url.mjs ${{ github.event.pull_request.html_url }} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -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'; | ||||||||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit: since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I try to not rely on Node.js-only globals when writing ES modules to ease a potential port to the browser. I really don't feel strongly about that, and am willing to remove the import if anyone disagrees.
Every time we try to introduce a new module in core comes the question of how breaking it would be for the ecosystem (is there a module that use the same name out there). It's been discussed several time to add a prefix to core modules, and with ESM we had to come up with a URL scheme to be spec compliant. TSC has decided that it will be ported to the CJS resolver as well (see #36098), so why not use it. |
||||||||
|
||||||||
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; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
let currentFile; | ||||||||
let currentLine; | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
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])) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
console.warn( | ||||||||
`::warning file=${currentFile},line=${currentLine++},col=${line.length}` + | ||||||||
aduh95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
'::pr-url doesn\'t match the actual PR URL.' | ||||||||
); | ||||||||
} else if (line[0] !== '-') { | ||||||||
// Increment line counter if line is not being deleted. | ||||||||
currentLine++; | ||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this supposed to be the check here (based on the above jobs)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to check only pull request (it wouldn't work on push, because it needs a PR URL), and I believe it's fine to have it running on draft PRs because it doesn't produce errors.