Skip to content

Commit

Permalink
feat(gitlab): Allow descriptions longer than 25K characters (#9452)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgblomqvist committed Apr 8, 2021
1 parent 63b6cf6 commit a2aa5ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
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

0 comments on commit a2aa5ce

Please sign in to comment.