From bfdbbea71c4fbeeb1f959bd7003db32b61e13d47 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Tue, 10 Aug 2021 22:13:49 +0200 Subject: [PATCH] Revert "fix(github): Better massageMarkdown implementation (#11133)" This reverts commit 0da13d1c189bb9a24ac071030aefff0061ae3111. --- .../github/__snapshots__/index.spec.ts.snap | 5 +- lib/platform/github/index.ts | 3 +- .../github/massage-markdown-links.spec.ts | 35 ------------ lib/platform/github/massage-markdown-links.ts | 55 ------------------- package.json | 3 - yarn.lock | 14 ++--- 6 files changed, 9 insertions(+), 106 deletions(-) delete mode 100644 lib/platform/github/massage-markdown-links.spec.ts delete mode 100644 lib/platform/github/massage-markdown-links.ts diff --git a/lib/platform/github/__snapshots__/index.spec.ts.snap b/lib/platform/github/__snapshots__/index.spec.ts.snap index 1d4e3fffee25c7..bf111b17ecb9af 100644 --- a/lib/platform/github/__snapshots__/index.spec.ts.snap +++ b/lib/platform/github/__snapshots__/index.spec.ts.snap @@ -7772,10 +7772,7 @@ Array [ ] `; -exports[`platform/github/index massageMarkdown(input) returns updated pr body 1`] = ` -"[https://github.com/foo/bar/issues/5](https://togithub.com/foo/bar/issues/5) plus also [a link](https://togithub.com/foo/bar/issues/5) -" -`; +exports[`platform/github/index massageMarkdown(input) returns updated pr body 1`] = `"https://github.com/foo/bar/issues/5 plus also [a link](https://togithub.com/foo/bar/issues/5)"`; exports[`platform/github/index mergePr(prNo) - autodetection should give up 1`] = ` Array [ diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index a4c7070edbd720..0b7b05f7419141 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -49,7 +49,6 @@ import { repoInfoQuery, vulnerabilityAlertsQuery, } from './graphql'; -import { massageMarkdownLinks } from './massage-markdown-links'; import { BranchProtection, CombinedBranchStatus, @@ -1570,7 +1569,7 @@ export function massageMarkdown(input: string): string { if (config.isGhe) { return smartTruncate(input, 60000); } - const massagedInput = massageMarkdownLinks(input) + const massagedInput = input // to be safe, replace all github.com links with renovatebot redirector .replace(/href="https?:\/\/github.com\//g, 'href="https://togithub.com/') .replace(/]\(https:\/\/github\.com\//g, '](https://togithub.com/') diff --git a/lib/platform/github/massage-markdown-links.spec.ts b/lib/platform/github/massage-markdown-links.spec.ts deleted file mode 100644 index 9908a7615bd6ea..00000000000000 --- a/lib/platform/github/massage-markdown-links.spec.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getName } from '../../../test/util'; -import { massageMarkdownLinks } from './massage-markdown-links'; - -describe(getName(), () => { - const table = [ - ['github.com', '[github.com](togithub.com)'], - ['www.github.com', '[www.github.com](www.togithub.com)'], - ['api.github.com', 'api.github.com'], - ['togithub.com', 'togithub.com'], - ['foobartogithub.com', 'foobartogithub.com'], - ['[github.com](github.com)', '[github.com](togithub.com)'], - ['[github.com](www.github.com)', '[github.com](www.togithub.com)'], - [ - '[github.com](https://github.com/foo/bar)', - '[github.com](https://togithub.com/foo/bar)', - ], - [ - 'https://github.com/foo/bar', - '[https://github.com/foo/bar](https://togithub.com/foo/bar)', - ], - [ - '[foobar](https://github.com/foo/bar)', - '[foobar](https://togithub.com/foo/bar)', - ], - [ - '[https://github.com/foo/bar](https://github.com/foo/bar)', - '[https://github.com/foo/bar](https://togithub.com/foo/bar)', - ], - ]; - - test.each(table)('%s -> %s', (input, output) => { - const res = massageMarkdownLinks(input).trimRight(); - expect(res).toEqual(output); - }); -}); diff --git a/lib/platform/github/massage-markdown-links.ts b/lib/platform/github/massage-markdown-links.ts deleted file mode 100644 index ccec71852d1d1f..00000000000000 --- a/lib/platform/github/massage-markdown-links.ts +++ /dev/null @@ -1,55 +0,0 @@ -import findAndReplace from 'mdast-util-find-and-replace'; -import remark from 'remark'; -import type { Plugin, Transformer } from 'unified'; -// eslint-disable-next-line import/no-unresolved -import type { Node } from 'unist'; -import visit from 'unist-util-visit'; -import { logger } from '../../logger'; - -const urlRegex = - /(?:https?:)?(?:\/\/)?(?:www\.)?(? { - if (node?.url) { - // eslint-disable-next-line no-param-reassign - node.url = massageLink(node.url); - } - }); -} - -const githubExtra: Plugin = (): Transformer => transformer; - -export function massageMarkdownLinks(content: string): string { - try { - const output = remark().use(githubExtra).processSync(content); - return output.toString(); - } catch (err) /* istanbul ignore next */ { - logger.warn({ err }, `Unable to massage markdown text`); - return content; - } -} diff --git a/package.json b/package.json index e5a13244f90218..d90dbaaa45722f 100644 --- a/package.json +++ b/package.json @@ -167,8 +167,6 @@ "luxon": "2.0.1", "markdown-it": "12.2.0", "markdown-table": "2.0.0", - "mdast-util-find-and-replace": "1.1.1", - "mdast-util-to-string": "2.0.0", "minimatch": "3.0.4", "moo": "0.5.1", "node-html-parser": "3.3.6", @@ -189,7 +187,6 @@ "simple-git": "2.42.0", "slugify": "1.6.0", "traverse": "0.6.6", - "unist-util-visit": "2.0.3", "upath": "2.0.1", "url-join": "4.0.1", "validate-npm-package-name": "3.0.0", diff --git a/yarn.lock b/yarn.lock index 378f94e3a71fa2..7fdd171f0227f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6507,7 +6507,7 @@ matcher@^3.0.0: dependencies: escape-string-regexp "^4.0.0" -mdast-util-find-and-replace@1.1.1, mdast-util-find-and-replace@^1.0.0: +mdast-util-find-and-replace@^1.0.0: version "1.1.1" resolved "https://registry.yarnpkg.com/mdast-util-find-and-replace/-/mdast-util-find-and-replace-1.1.1.tgz#b7db1e873f96f66588c321f1363069abf607d1b5" integrity sha512-9cKl33Y21lyckGzpSmEQnIDjEfeeWelN5s1kUW1LwdB0Fkuq2u+4GdqcGEygYxJE8GVqCl0741bYXHgamfWAZA== @@ -6539,16 +6539,16 @@ mdast-util-to-markdown@^0.6.0: repeat-string "^1.0.0" zwitch "^1.0.0" -mdast-util-to-string@2.0.0, mdast-util-to-string@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/mdast-util-to-string/-/mdast-util-to-string-2.0.0.tgz#b8cfe6a713e1091cb5b728fc48885a4767f8b97b" - integrity sha512-AW4DRS3QbBayY/jJmD8437V1Gombjf8RSOUCMFBuo5iHi58AGEgVCKQ+ezHkZZDpAQS75hcBMpLqjpJTjtUL7w== - mdast-util-to-string@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/mdast-util-to-string/-/mdast-util-to-string-1.1.0.tgz#27055500103f51637bd07d01da01eb1967a43527" integrity sha512-jVU0Nr2B9X3MU4tSK7JP1CMkSvOj7X5l/GboG1tKRw52lLF1x2Ju92Ms9tNetCcbfX3hzlM73zYo2NKkWSfF/A== +mdast-util-to-string@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/mdast-util-to-string/-/mdast-util-to-string-2.0.0.tgz#b8cfe6a713e1091cb5b728fc48885a4767f8b97b" + integrity sha512-AW4DRS3QbBayY/jJmD8437V1Gombjf8RSOUCMFBuo5iHi58AGEgVCKQ+ezHkZZDpAQS75hcBMpLqjpJTjtUL7w== + mdurl@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e" @@ -9455,7 +9455,7 @@ unist-util-visit-parents@^3.0.0: "@types/unist" "^2.0.0" unist-util-is "^4.0.0" -unist-util-visit@2.0.3, unist-util-visit@^2.0.0: +unist-util-visit@^2.0.0: version "2.0.3" resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-2.0.3.tgz#c3703893146df47203bb8a9795af47d7b971208c" integrity sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q==