Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gitlab): Allow descriptions longer than 25K characters #9452

Merged
merged 1 commit into from Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/platform/gitlab/index.spec.ts
Expand Up @@ -1512,6 +1512,7 @@ describe('platform/gitlab', () => {
expect(httpMock.getTrace()).toMatchSnapshot();
});
});

const prBody = `https://github.com/foo/bar/issues/5 plus also [a link](https://github.com/foo/bar/issues/5

Pull Requests are the best, here are some PRs.
Expand All @@ -1522,11 +1523,28 @@ 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('massageMarkdown(input)', () => {
it('returns updated pr body', () => {
it('returns updated pr body', async () => {
jest.mock('../utils/pr-body');
const { smartTruncate } = require('../utils/pr-body');

await initFakePlatform('13.4.0');
expect(gitlab.massageMarkdown(prBody)).toMatchSnapshot();
expect(smartTruncate).not.toHaveBeenCalled();
});

it('truncates description if too low API version', async () => {
jest.mock('../utils/pr-body');
const { smartTruncate } = require('../utils/pr-body');

await initFakePlatform('13.3.0');
gitlab.massageMarkdown(prBody);
expect(smartTruncate).toHaveBeenCalledTimes(1);
expect(smartTruncate).toHaveBeenCalledWith(expect.any(String), 25000);
});
});

describe('getVulnerabilityAlerts()', () => {
it('returns empty', async () => {
const res = await gitlab.getVulnerabilityAlerts();
Expand Down
22 changes: 15 additions & 7 deletions lib/platform/gitlab/index.ts
Expand Up @@ -608,13 +608,21 @@ export async function mergePr(iid: number): Promise<boolean> {
}

export function massageMarkdown(input: string): string {
return smartTruncate(
input
.replace(/Pull Request/g, 'Merge Request')
.replace(/PR/g, 'MR')
.replace(/\]\(\.\.\/pull\//g, '](!'),
25000 // TODO: increase it once https://gitlab.com/gitlab-org/gitlab/-/issues/217483 is closed
);
let desc = input
.replace(/Pull Request/g, 'Merge Request')
.replace(/PR/g, 'MR')
.replace(/\]\(\.\.\/pull\//g, '](!');

if (lt(defaults.version, '13.4.0')) {
logger.debug(
{ version: defaults.version },
'GitLab versions earlier than 13.4 have issues with long descriptions, truncating to 25K characters'
);

desc = smartTruncate(desc, 25000);
}

return desc;
}

// Branch
Expand Down