From 399d7ea73ec6a880217e00ed0484d6ec15c77f10 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Sun, 28 Feb 2021 19:19:35 +0100 Subject: [PATCH] refactor: platform.getPrBody -> massageMarkdown (#8787) --- lib/platform/azure/__snapshots__/index.spec.ts.snap | 2 +- lib/platform/azure/index.spec.ts | 4 ++-- lib/platform/azure/index.ts | 2 +- .../bitbucket-server/__snapshots__/index.spec.ts.snap | 8 ++++---- lib/platform/bitbucket-server/index.spec.ts | 6 +++--- lib/platform/bitbucket-server/index.ts | 4 ++-- lib/platform/bitbucket/__snapshots__/index.spec.ts.snap | 2 +- lib/platform/bitbucket/index.spec.ts | 4 ++-- lib/platform/bitbucket/index.ts | 4 ++-- lib/platform/common.ts | 2 +- lib/platform/gitea/index.spec.ts | 4 ++-- lib/platform/gitea/index.ts | 4 ++-- lib/platform/github/__snapshots__/index.spec.ts.snap | 4 ++-- lib/platform/github/index.spec.ts | 6 +++--- lib/platform/github/index.ts | 2 +- lib/platform/gitlab/__snapshots__/index.spec.ts.snap | 2 +- lib/platform/gitlab/index.spec.ts | 4 ++-- lib/platform/gitlab/index.ts | 4 ++-- lib/workers/branch/index.ts | 2 +- lib/workers/pr/body/index.ts | 2 +- lib/workers/pr/index.spec.ts | 2 +- lib/workers/pr/index.ts | 2 +- lib/workers/repository/onboarding/pr/index.spec.ts | 2 +- lib/workers/repository/onboarding/pr/index.ts | 2 +- 24 files changed, 40 insertions(+), 40 deletions(-) diff --git a/lib/platform/azure/__snapshots__/index.spec.ts.snap b/lib/platform/azure/__snapshots__/index.spec.ts.snap index 639d7254a5..8b419d878c 100644 --- a/lib/platform/azure/__snapshots__/index.spec.ts.snap +++ b/lib/platform/azure/__snapshots__/index.spec.ts.snap @@ -199,7 +199,7 @@ Object { } `; -exports[`platform/azure getPrBody(input) returns updated pr body 1`] = `"https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5)"`; +exports[`platform/azure massageMarkdown(input) returns updated pr body 1`] = `"https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5)"`; exports[`platform/azure getRepos() should return an array of repos 1`] = ` Array [ diff --git a/lib/platform/azure/index.spec.ts b/lib/platform/azure/index.spec.ts index 5151d362a4..9dc59672a6 100644 --- a/lib/platform/azure/index.spec.ts +++ b/lib/platform/azure/index.spec.ts @@ -938,11 +938,11 @@ describe('platform/azure', () => { }); }); - describe('getPrBody(input)', () => { + describe('massageMarkdown(input)', () => { it('returns updated pr body', () => { const input = '<details>https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5)'; - expect(azure.getPrBody(input)).toMatchSnapshot(); + expect(azure.massageMarkdown(input)).toMatchSnapshot(); }); }); diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 4b11286c7c..59ce57dff9 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -654,7 +654,7 @@ export async function mergePr( } } -export function getPrBody(input: string): string { +export function massageMarkdown(input: string): string { // Remove any HTML we use return smartTruncate(input, 4000) .replace( diff --git a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap index 1f3af18f51..95196af688 100644 --- a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap @@ -2310,9 +2310,9 @@ Array [ exports[`platform/bitbucket-server/index endpoint with no path getPr() returns null for no prNo 1`] = `Array []`; -exports[`platform/bitbucket-server/index endpoint with no path getPrBody() returns diff files 1`] = `"**foo**bartext"`; +exports[`platform/bitbucket-server/index endpoint with no path massageMarkdown() returns diff files 1`] = `"**foo**bartext"`; -exports[`platform/bitbucket-server/index endpoint with no path getPrBody() sanitizes HTML comments in the body 1`] = ` +exports[`platform/bitbucket-server/index endpoint with no path massageMarkdown() sanitizes HTML comments in the body 1`] = ` "--- - [ ] If you want to rebase/retry this PR, check this box @@ -6400,9 +6400,9 @@ Array [ exports[`platform/bitbucket-server/index endpoint with path getPr() returns null for no prNo 1`] = `Array []`; -exports[`platform/bitbucket-server/index endpoint with path getPrBody() returns diff files 1`] = `"**foo**bartext"`; +exports[`platform/bitbucket-server/index endpoint with path massageMarkdown() returns diff files 1`] = `"**foo**bartext"`; -exports[`platform/bitbucket-server/index endpoint with path getPrBody() sanitizes HTML comments in the body 1`] = ` +exports[`platform/bitbucket-server/index endpoint with path massageMarkdown() sanitizes HTML comments in the body 1`] = ` "--- - [ ] If you want to rebase/retry this PR, check this box diff --git a/lib/platform/bitbucket-server/index.spec.ts b/lib/platform/bitbucket-server/index.spec.ts index aac0a28478..f2f29b3dff 100644 --- a/lib/platform/bitbucket-server/index.spec.ts +++ b/lib/platform/bitbucket-server/index.spec.ts @@ -1698,17 +1698,17 @@ describe(getName(__filename), () => { }); }); - describe('getPrBody()', () => { + describe('massageMarkdown()', () => { it('returns diff files', () => { expect( - bitbucket.getPrBody( + bitbucket.massageMarkdown( '<details><summary>foo</summary>bar</details>text<details>' ) ).toMatchSnapshot(); }); it('sanitizes HTML comments in the body', () => { - const prBody = bitbucket.getPrBody(`--- + const prBody = bitbucket.massageMarkdown(`--- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box - [ ] <!-- recreate-branch=renovate/docker-renovate-renovate-16.x --><a href="/some/link">Update renovate/renovate to 16.1.2</a> diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index bb07c4e1cf..8b785124b1 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -985,8 +985,8 @@ export async function mergePr( return true; } -export function getPrBody(input: string): string { - logger.debug(`getPrBody(${input.split('\n')[0]})`); +export function massageMarkdown(input: string): string { + logger.debug(`massageMarkdown(${input.split('\n')[0]})`); // Remove any HTML we use return smartTruncate(input, 30000) .replace( diff --git a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap index c5ead11ef5..b399274895 100644 --- a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap @@ -1040,7 +1040,7 @@ Array [ ] `; -exports[`platform/bitbucket getPrBody() returns diff files 1`] = `"**foo**bartext"`; +exports[`platform/bitbucket massageMarkdown() returns diff files 1`] = `"**foo**bartext"`; exports[`platform/bitbucket getPrList() filters PR list by author 1`] = ` Array [ diff --git a/lib/platform/bitbucket/index.spec.ts b/lib/platform/bitbucket/index.spec.ts index b3363320c8..18ae7caca5 100644 --- a/lib/platform/bitbucket/index.spec.ts +++ b/lib/platform/bitbucket/index.spec.ts @@ -726,10 +726,10 @@ describe('platform/bitbucket', () => { }); }); - describe('getPrBody()', () => { + describe('massageMarkdown()', () => { it('returns diff files', () => { expect( - bitbucket.getPrBody( + bitbucket.massageMarkdown( '<details><summary>foo</summary>bar</details>text<details>' ) ).toMatchSnapshot(); diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index f0edfd32c8..3a45348c40 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -460,7 +460,7 @@ async function closeIssue(issueNumber: number): Promise<void> { ); } -export function getPrBody(input: string): string { +export function massageMarkdown(input: string): string { // Remove any HTML we use return smartTruncate(input, 50000) .replace( @@ -479,7 +479,7 @@ export async function ensureIssue({ body, }: EnsureIssueConfig): Promise<EnsureIssueResult | null> { logger.debug(`ensureIssue()`); - const description = getPrBody(sanitize(body)); + const description = massageMarkdown(sanitize(body)); /* istanbul ignore if */ if (!config.has_issues) { diff --git a/lib/platform/common.ts b/lib/platform/common.ts index f09ef6ed77..886b41f031 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -152,7 +152,7 @@ export interface Platform { ensureIssue( issueConfig: EnsureIssueConfig ): Promise<EnsureIssueResult | null>; - getPrBody(prBody: string): string; + massageMarkdown(prBody: string): string; updatePr(prConfig: UpdatePrConfig): Promise<void>; mergePr(number: number, branchName: string): Promise<boolean>; addReviewers(number: number, reviewers: string[]): Promise<void>; diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index 146dda9c66..be9ceeafe1 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -1313,11 +1313,11 @@ describe('platform/gitea', () => { }); }); - describe('getPrBody', () => { + describe('massageMarkdown', () => { it('should truncate body to 1000000 characters', () => { const excessiveBody = '*'.repeat(1000001); - expect(gitea.getPrBody(excessiveBody)).toHaveLength(1000000); + expect(gitea.massageMarkdown(excessiveBody)).toHaveLength(1000000); }); }); diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index a028bf8ed2..7b6dd1f694 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -800,7 +800,7 @@ const platform: Platform = { } }, - getPrBody(prBody: string): string { + massageMarkdown(prBody: string): string { return smartTruncate(smartLinks(prBody), 1000000); }, @@ -827,7 +827,7 @@ export const { getJsonFile, getIssueList, getPr, - getPrBody, + massageMarkdown, getPrList, getRepoForceRebase, getRepos, diff --git a/lib/platform/github/__snapshots__/index.spec.ts.snap b/lib/platform/github/__snapshots__/index.spec.ts.snap index d51b08c1e0..364f976566 100644 --- a/lib/platform/github/__snapshots__/index.spec.ts.snap +++ b/lib/platform/github/__snapshots__/index.spec.ts.snap @@ -4199,7 +4199,7 @@ Array [ ] `; -exports[`platform/github getPrBody(input) returns not-updated pr body for GHE 1`] = ` +exports[`platform/github massageMarkdown(input) returns not-updated pr body for GHE 1`] = ` Array [ Object { "headers": Object { @@ -4261,7 +4261,7 @@ Array [ ] `; -exports[`platform/github getPrBody(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 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 getRepoForceRebase should detect repoForceRebase 1`] = ` Array [ diff --git a/lib/platform/github/index.spec.ts b/lib/platform/github/index.spec.ts index 2f35b846cc..f0a0c5ae56 100644 --- a/lib/platform/github/index.spec.ts +++ b/lib/platform/github/index.spec.ts @@ -1852,11 +1852,11 @@ describe('platform/github', () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); }); - describe('getPrBody(input)', () => { + describe('massageMarkdown(input)', () => { it('returns updated pr body', () => { const input = 'https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5)'; - expect(github.getPrBody(input)).toMatchSnapshot(); + expect(github.massageMarkdown(input)).toMatchSnapshot(); }); it('returns not-updated pr body for GHE', async () => { const scope = httpMock @@ -1880,7 +1880,7 @@ describe('platform/github', () => { } as any); const input = 'https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5)'; - expect(github.getPrBody(input)).toEqual(input); + expect(github.massageMarkdown(input)).toEqual(input); expect(httpMock.getTrace()).toMatchSnapshot(); }); }); diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 0450a4c20f..5ba50d313d 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -1574,7 +1574,7 @@ export async function mergePr( return true; } -export function getPrBody(input: string): string { +export function massageMarkdown(input: string): string { if (config.isGhe) { return smartTruncate(input, 60000); } diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap index 5f12ade0c5..2e6a2fd131 100644 --- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap @@ -1714,7 +1714,7 @@ Array [ ] `; -exports[`platform/gitlab getPrBody(input) returns updated pr body 1`] = ` +exports[`platform/gitlab massageMarkdown(input) returns updated pr body 1`] = ` "https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5 Merge Requests are the best, here are some MRs. diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index 04b889d634..0755bbd7d4 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -1364,9 +1364,9 @@ These updates have all been created already. Click a checkbox below to force a r - [ ] <!-- rebase-branch=renovate/major-got-packages -->[build(deps): update got packages (major)](../pull/2433) (\`gh-got\`, \`gl-got\`, \`got\`) `; - describe('getPrBody(input)', () => { + describe('massageMarkdown(input)', () => { it('returns updated pr body', () => { - expect(gitlab.getPrBody(prBody)).toMatchSnapshot(); + expect(gitlab.massageMarkdown(prBody)).toMatchSnapshot(); }); }); describe('getVulnerabilityAlerts()', () => { diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index b15e6ed790..e3001c99cd 100755 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -596,7 +596,7 @@ export async function mergePr(iid: number): Promise<boolean> { } } -export function getPrBody(input: string): string { +export function massageMarkdown(input: string): string { return smartTruncate( input .replace(/Pull Request/g, 'Merge Request') @@ -764,7 +764,7 @@ export async function ensureIssue({ body, }: EnsureIssueConfig): Promise<'updated' | 'created' | null> { logger.debug(`ensureIssue()`); - const description = getPrBody(sanitize(body)); + const description = massageMarkdown(sanitize(body)); try { const issueList = await getIssueList(); let issue = issueList.find((i) => i.title === title); diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index 25f6bf3824..1cfa41636e 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -658,7 +658,7 @@ export async function processBranch( content += `##### File name: ${error.lockFile}\n\n`; content += `\`\`\`\n${error.stderr}\n\`\`\`\n\n`; }); - content = platform.getPrBody(content); + content = platform.massageMarkdown(content); if ( !( config.suppressNotifications.includes('artifactErrors') || diff --git a/lib/workers/pr/body/index.ts b/lib/workers/pr/body/index.ts index bf94c4f37b..c6f1e61a03 100644 --- a/lib/workers/pr/body/index.ts +++ b/lib/workers/pr/body/index.ts @@ -85,6 +85,6 @@ export async function getPrBody(config: BranchConfig): Promise<string> { let prBody = template.compile(prBodyTemplate, content, false); prBody = prBody.trim(); prBody = prBody.replace(/\n\n\n+/g, '\n\n'); - prBody = platform.getPrBody(prBody); + prBody = platform.massageMarkdown(prBody); return prBody; } diff --git a/lib/workers/pr/index.spec.ts b/lib/workers/pr/index.spec.ts index 028d6b3d61..b8092fc489 100644 --- a/lib/workers/pr/index.spec.ts +++ b/lib/workers/pr/index.spec.ts @@ -201,7 +201,7 @@ describe('workers/pr', () => { displayNumber: 'New Pull Request', } as never); config.upgrades = [config]; - platform.getPrBody = jest.fn((input) => input); + platform.massageMarkdown = jest.fn((input) => input); platform.getBranchPr = jest.fn(); platform.getBranchStatus = jest.fn(); }); diff --git a/lib/workers/pr/index.ts b/lib/workers/pr/index.ts index bb038eefda..716180c0ea 100644 --- a/lib/workers/pr/index.ts +++ b/lib/workers/pr/index.ts @@ -435,7 +435,7 @@ export async function ensurePr( if (config.branchAutomergeFailureMessage === 'branch status error') { content += '\n___\n * Branch has one or more failed status checks'; } - content = platform.getPrBody(content); + content = platform.massageMarkdown(content); logger.debug('Adding branch automerge failure message to PR'); // istanbul ignore if if (getAdminConfig().dryRun) { diff --git a/lib/workers/repository/onboarding/pr/index.spec.ts b/lib/workers/repository/onboarding/pr/index.spec.ts index 6b9e02b4a2..6ddb61ea17 100644 --- a/lib/workers/repository/onboarding/pr/index.spec.ts +++ b/lib/workers/repository/onboarding/pr/index.spec.ts @@ -29,7 +29,7 @@ describe('workers/repository/onboarding/pr', () => { }; packageFiles = { npm: [{ packageFile: 'package.json', deps: [] }] }; branches = []; - platform.getPrBody = jest.fn((input) => input); + platform.massageMarkdown = jest.fn((input) => input); platform.createPr.mockResolvedValueOnce(partial<Pr>({})); setAdminConfig(); }); diff --git a/lib/workers/repository/onboarding/pr/index.ts b/lib/workers/repository/onboarding/pr/index.ts index d688979211..3b478a51d4 100644 --- a/lib/workers/repository/onboarding/pr/index.ts +++ b/lib/workers/repository/onboarding/pr/index.ts @@ -102,7 +102,7 @@ If you need any further assistance then you can also [request help here](${confi } logger.trace('prBody:\n' + prBody); - prBody = platform.getPrBody(prBody); + prBody = platform.massageMarkdown(prBody); if (existingPr) { logger.debug('Found open onboarding PR'); -- GitLab