Skip to content

Commit

Permalink
refactor: platform.getPrBody -> massageMarkdown (#8787)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 28, 2021
1 parent b5e6279 commit 399d7ea
Show file tree
Hide file tree
Showing 24 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lib/platform/azure/__snapshots__/index.spec.ts.snap
Expand Up @@ -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 [
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/azure/index.spec.ts
Expand Up @@ -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();
});
});

Expand Down
2 changes: 1 addition & 1 deletion lib/platform/azure/index.ts
Expand Up @@ -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(
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/platform/bitbucket-server/index.spec.ts
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/bitbucket-server/index.ts
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/bitbucket/__snapshots__/index.spec.ts.snap
Expand Up @@ -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 [
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/bitbucket/index.spec.ts
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/bitbucket/index.ts
Expand Up @@ -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(
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/common.ts
Expand Up @@ -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>;
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/gitea/index.spec.ts
Expand Up @@ -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);
});
});

Expand Down
4 changes: 2 additions & 2 deletions lib/platform/gitea/index.ts
Expand Up @@ -800,7 +800,7 @@ const platform: Platform = {
}
},

getPrBody(prBody: string): string {
massageMarkdown(prBody: string): string {
return smartTruncate(smartLinks(prBody), 1000000);
},

Expand All @@ -827,7 +827,7 @@ export const {
getJsonFile,
getIssueList,
getPr,
getPrBody,
massageMarkdown,
getPrList,
getRepoForceRebase,
getRepos,
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/github/__snapshots__/index.spec.ts.snap
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 [
Expand Down
6 changes: 3 additions & 3 deletions lib/platform/github/index.spec.ts
Expand Up @@ -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
Expand All @@ -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();
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/github/index.ts
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/gitlab/__snapshots__/index.spec.ts.snap
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/gitlab/index.spec.ts
Expand Up @@ -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()', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/gitlab/index.ts
Expand Up @@ -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')
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/branch/index.ts
Expand Up @@ -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') ||
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/pr/body/index.ts
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion lib/workers/pr/index.spec.ts
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/pr/index.ts
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/onboarding/pr/index.spec.ts
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/onboarding/pr/index.ts
Expand Up @@ -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');
Expand Down

0 comments on commit 399d7ea

Please sign in to comment.