Skip to content

Commit

Permalink
convert file paths to GitHub code links
Browse files Browse the repository at this point in the history
  • Loading branch information
OnkarRuikar committed Sep 4, 2024
1 parent 2e5c6c9 commit 0fc1ea1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/spelling-check-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
npm install
echo Running spelling check...
output=$(npx cspell --no-progress --gitignore --config .vscode/cspell.json "**/*.md" || exit 0)
output=$(node scripts/linkify-logs.js "${output}")
output=$(echo "$output" | sed 's/^/- /')
echo "$output"
echo "OUTPUT<<EOF" >> $GITHUB_ENV
echo "$output" >> $GITHUB_ENV
Expand All @@ -35,16 +37,13 @@ jobs:
comment_body=$(cat<<EOM
Typos and unknown words:
~~~
${OUTPUT}
~~~
> [!TIP]
> To exclude words from the spellchecker, you can add valid words (web technology terms or abbreviations) to the [terms-abbreviations.txt](https://github.com/mdn/content/blob/main/.vscode/terms-abbreviations.txt) dictionary for IDE autocompletion. To ignore strings that are not words (\`AABBCC\` in code, for instance), you can add them to [ignore-list.txt](https://github.com/mdn/content/blob/main/.vscode/ignore-list.txt).
EOM
)
comment_body+=$'\n\n'$(echo "(comment last updated: $(date +'%Y-%m-%d %H:%M:%S'))")
gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
Expand Down
16 changes: 16 additions & 0 deletions scripts/linkify-logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* The script converts file paths to GitHub source links in the provided text.
* Usage: node scripts/linkify-logs.js ${logs}
*/

const logs = process.argv[2];

console.log(
logs.replaceAll(/(files\/.*?\/index.md):?(\d+)?/g, (_, path, lineNo) => {
let link = `[${path}](https://github.com/mdn/content/blob/main/${path}?plain=1`;
if (lineNo) {
return link + `#L${lineNo}):${lineNo}`;
}
return link + `)`;
}),
);

0 comments on commit 0fc1ea1

Please sign in to comment.