File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 9898 - uses : mszostok/codeowners-validator@v0.4.0
9999 with :
100100 checks : " files,duppatterns"
101+ lint-pr-url :
102+ if : ${{ github.event.pull_request }}
103+ runs-on : ubuntu-latest
104+ steps :
105+ - uses : actions/checkout@v2
106+ with :
107+ fetch-depth : 2
108+ # GH Actions squashes all PR commits, HEAD^ refers to the base branch.
109+ - 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 1+ #!/usr/bin/env node
2+
3+ // Usage:
4+ // git diff upstream/master...HEAD -G"pr-url:" -- "*.md" | \
5+ // ./tools/lint-pr-url.mjs <expected-pr-url>
6+
7+ import process from 'node:process' ;
8+ import readline from 'node:readline' ;
9+
10+ const [ , , expectedPrUrl ] = process . argv ;
11+
12+ const fileDelimiter = / ^ \+ \+ \+ b \/ ( .+ \. m d ) $ / ;
13+ const changeDelimiter = / ^ @ @ - \d + , \d + \+ ( \d + ) , \d + @ @ / ;
14+ const prUrlDefinition = / ^ \+ \s + p r - u r l : ( .+ ) $ / ;
15+
16+ const validatePrUrl = ( url ) => url == null || url === expectedPrUrl ;
17+
18+ let currentFile ;
19+ let currentLine ;
20+
21+ const diff = readline . createInterface ( { input : process . stdin } ) ;
22+ for await ( const line of diff ) {
23+ if ( fileDelimiter . test ( line ) ) {
24+ currentFile = line . match ( fileDelimiter ) [ 1 ] ;
25+ console . log ( `Parsing changes in ${ currentFile } .` ) ;
26+ } else if ( changeDelimiter . test ( line ) ) {
27+ currentLine = Number ( line . match ( changeDelimiter ) [ 1 ] ) ;
28+ } else if ( ! validatePrUrl ( line . match ( prUrlDefinition ) ?. [ 1 ] ) ) {
29+ console . warn (
30+ `::warning file=${ currentFile } ,line=${ currentLine ++ } ,col=${ line . length } ` +
31+ '::pr-url doesn\'t match the actual PR URL.'
32+ ) ;
33+ } else if ( line [ 0 ] !== '-' ) {
34+ // Increment line counter if line is not being deleted.
35+ currentLine ++ ;
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments