Skip to content

Commit

Permalink
some improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasAtSAP committed Aug 23, 2023
1 parent 5484889 commit 1974199
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions .github/etc/create-review.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ Generally, for each spelling mistake there are 2 ways to fix it:
2. The word is incorrectly reported as misspelled → put the word on the **project-words.txt** list, located in the root project directory.
`

const getInvalidUrlText = () => 'Please use wellformed URLs: Only use `http://<url>` for localhost links.'
const getInvalidUrlText = (link) => {
const updatedLink = link.includes('localhost') ? 'http' : 'https' + '://' + link.split('/').slice(1).join('/')

return createSuggestionText(updatedLink) + 'Please use wellformed URLs.'
}

const escapeMarkdownlink = (link) => link.replace(/(\[|\(|\]|\))/g, "\\$1")

const

module.exports = async ({ github, require, exec, core }) => {
const { readFileSync, existsSync } = require('fs')
Expand Down Expand Up @@ -102,10 +110,10 @@ module.exports = async ({ github, require, exec, core }) => {
}

if (rule === 'MD042/no-empty-links') {
contextText = context.trim()

const link = context.match(/\[Context: "(\[.*?\]\(\))"/)[1]

contextText = `[Context: "${escapeMarkdownlink(link)}"]`

const { position } = await findPositionInDiff(link, path)

if (position < 0) {
Expand Down Expand Up @@ -136,18 +144,18 @@ module.exports = async ({ github, require, exec, core }) => {
const ruleName = details.split(':')[0].slice(1)

if (ruleName === 'only-wellformed-urls') {
const invalidLink = context.match(/\[Context:.*(\[.*\]\(.*\)).*\]/)[1]
const [, text, link] = context.match(/\[Context:.*(\[.*\])(\(.*\)).*\]/)

description = 'Only use wellformed URLs'
contextText = `[Context: "${invalidLink}"]`
contextText = `[Context: "${escapeMarkdownlink(text + link)}"]`

const { line, position } = await findPositionInDiff(invalidLink, path)

if (!line || position < 0) {
continue
}

comments.push({ path, position, body: getInvalidUrlText() })
comments.push({ path, position, body: getInvalidUrlText(link.slice(1, -1)) })
}
}

Expand Down

0 comments on commit 1974199

Please sign in to comment.