| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,3 +92,12 @@ jobs: | |||
| 92 | 92 | - uses: mszostok/codeowners-validator@v0.4.0 | |
| 93 | 93 | with: | |
| 94 | 94 | checks: "files,duppatterns" | |
| 95 | + lint-pr-url: | ||
| 96 | + if: ${{ github.event.pull_request }} | ||
| 97 | + runs-on: ubuntu-latest | ||
| 98 | + steps: | ||
| 99 | + - uses: actions/checkout@v2 | ||
| 100 | + with: | ||
| 101 | + fetch-depth: 2 | ||
| 102 | + # GH Actions squashes all PR commits, HEAD^ refers to the base branch. | ||
| 103 | + - 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 @@ | |||
| 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\/(.+\.md)$/; | ||
| 13 | + const changeDelimiter = /^@@ -\d+,\d+ \+(\d+),\d+ @@/; | ||
| 14 | + const prUrlDefinition = /^\+\s+pr-url: (.+)$/; | ||
| 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments