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: use comments if PR body is too long #31616

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/modules/platform/azure/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1985,4 +1985,16 @@ describe('modules/platform/azure/index', () => {
expect(res).toBeNull();
});
});

describe('maxBodyLength()', () => {
it('returns 4000', () => {
expect(azure.maxBodyLength()).toBe(4000);
});
});

describe('maxCommentLength()', () => {
it('returns 150000', () => {
expect(azure.maxCommentLength()).toBe(150000);
});
});
});
7 changes: 5 additions & 2 deletions lib/modules/platform/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import type {
UpdatePrConfig,
} from '../types';
import { getNewBranchName, repoFingerprint } from '../util';
import { smartTruncate } from '../utils/pr-body';
import * as azureApi from './azure-got-wrapper';
import * as azureHelper from './azure-helper';
import type { AzurePr } from './types';
Expand Down Expand Up @@ -811,7 +810,7 @@ export async function mergePr({

export function massageMarkdown(input: string): string {
// Remove any HTML we use
return smartTruncate(input, maxBodyLength())
return input
.replace(
'you tick the rebase/retry checkbox',
'rename PR to start with "rebase!"',
Expand All @@ -828,6 +827,10 @@ export function maxBodyLength(): number {
return 4000;
}

export function maxCommentLength(): number {
return 150000;
}

/* istanbul ignore next */
export function findIssue(): Promise<Issue | null> {
// TODO: Needs implementation (#9592)
Expand Down
12 changes: 12 additions & 0 deletions lib/modules/platform/bitbucket-server/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,18 @@ Followed by some information.
await expect(bitbucket.getJsonFile('file.json')).rejects.toThrow();
});
});

describe('maxBodyLength()', () => {
it('returns 30000', () => {
expect(bitbucket.maxBodyLength()).toBe(30000);
});
});

describe('maxCommentLength()', () => {
it('returns Infinity', () => {
expect(bitbucket.maxCommentLength()).toBe(Infinity);
});
});
});
});
});
7 changes: 5 additions & 2 deletions lib/modules/platform/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import type {
UpdatePrConfig,
} from '../types';
import { getNewBranchName, repoFingerprint } from '../util';
import { smartTruncate } from '../utils/pr-body';
import { UserSchema } from './schema';
import type {
BbsConfig,
Expand Down Expand Up @@ -1104,7 +1103,7 @@ export async function mergePr({
export function massageMarkdown(input: string): string {
logger.debug(`massageMarkdown(${input.split(newlineRegex)[0]})`);
// Remove any HTML we use
return smartTruncate(input, maxBodyLength())
return input
.replace(
'you tick the rebase/retry checkbox',
'rename PR to start with "rebase!"',
Expand All @@ -1122,3 +1121,7 @@ export function massageMarkdown(input: string): string {
export function maxBodyLength(): number {
return 30000;
}

export function maxCommentLength(): number {
return Infinity;
}
12 changes: 12 additions & 0 deletions lib/modules/platform/bitbucket/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1896,4 +1896,16 @@ describe('modules/platform/bitbucket/index', () => {
await expect(bitbucket.getJsonFile('file.json')).rejects.toThrow();
});
});

describe('maxBodyLength()', () => {
it('returns 50000', () => {
expect(bitbucket.maxBodyLength()).toBe(50000);
});
});

describe('maxCommentLength()', () => {
it('returns Infinity', () => {
expect(bitbucket.maxCommentLength()).toBe(Infinity);
});
});
});
7 changes: 5 additions & 2 deletions lib/modules/platform/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import type {
UpdatePrConfig,
} from '../types';
import { repoFingerprint } from '../util';
import { smartTruncate } from '../utils/pr-body';
import { readOnlyIssueBody } from '../utils/read-only-issue-body';
import * as comments from './comments';
import { BitbucketPrCache } from './pr-cache';
Expand Down Expand Up @@ -570,7 +569,7 @@ async function closeIssue(issueNumber: number): Promise<void> {

export function massageMarkdown(input: string): string {
// Remove any HTML we use
return smartTruncate(input, maxBodyLength())
return input
.replace(
'you tick the rebase/retry checkbox',
'by renaming this PR to start with "rebase!"',
Expand All @@ -590,6 +589,10 @@ export function maxBodyLength(): number {
return 50000;
}

export function maxCommentLength(): number {
return Infinity;
}

export async function ensureIssue({
title,
reuseTitle,
Expand Down
12 changes: 12 additions & 0 deletions lib/modules/platform/codecommit/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1327,4 +1327,16 @@ describe('modules/platform/codecommit/index', () => {
);
});
});

describe('maxBodyLength()', () => {
it('returns Infinity', () => {
expect(codeCommit.maxBodyLength()).toBe(Infinity);
});
});

describe('maxCommentLength()', () => {
it('returns Infinity', () => {
expect(codeCommit.maxCommentLength()).toBe(Infinity);
});
});
});
4 changes: 4 additions & 0 deletions lib/modules/platform/codecommit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ export function maxBodyLength(): number {
return Infinity;
}

export function maxCommentLength(): number {
return Infinity;
}

export async function getJsonFile(
fileName: string,
repoName?: string,
Expand Down
12 changes: 12 additions & 0 deletions lib/modules/platform/gerrit/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,4 +792,16 @@ describe('modules/platform/gerrit/index', () => {
await expect(gerrit.getIssueList()).resolves.toStrictEqual([]);
});
});

describe('maxBodyLength()', () => {
it('returns 16384', () => {
expect(gerrit.maxBodyLength()).toBe(16384);
});
});

describe('maxCommentLength()', () => {
it('returns Infinity', () => {
expect(gerrit.maxCommentLength()).toBe(Infinity);
});
});
});
7 changes: 5 additions & 2 deletions lib/modules/platform/gerrit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import type {
} from '../types';
import { repoFingerprint } from '../util';

import { smartTruncate } from '../utils/pr-body';
import { readOnlyIssueBody } from '../utils/read-only-issue-body';
import { client } from './client';
import { configureScm } from './scm';
Expand Down Expand Up @@ -396,7 +395,7 @@ export async function ensureComment(

export function massageMarkdown(prBody: string): string {
//TODO: do more Gerrit specific replacements?
return smartTruncate(readOnlyIssueBody(prBody), maxBodyLength())
return readOnlyIssueBody(prBody)
.replace(regEx(/Pull Request(s)?/g), 'Change-Request$1')
.replace(regEx(/\bPR(s)?\b/g), 'Change-Request$1')
.replace(regEx(/<\/?summary>/g), '**')
Expand All @@ -423,6 +422,10 @@ export function maxBodyLength(): number {
return 16384; //TODO: check the real gerrit limit (max. chars)
}

export function maxCommentLength(): number {
return Infinity;
}

export function deleteLabel(number: number, label: string): Promise<void> {
return Promise.resolve();
}
Expand Down
12 changes: 12 additions & 0 deletions lib/modules/platform/gitea/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2989,4 +2989,16 @@ describe('modules/platform/gitea/index', () => {
await expect(gitea.getJsonFile('file.json')).rejects.toThrow();
});
});

describe('maxBodyLength()', () => {
it('returns 1000000', () => {
expect(gitea.maxBodyLength()).toBe(1000000);
});
});

describe('maxCommentLength()', () => {
it('returns Infinity', () => {
expect(gitea.maxCommentLength()).toBe(Infinity);
});
});
});
8 changes: 6 additions & 2 deletions lib/modules/platform/gitea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import type {
UpdatePrConfig,
} from '../types';
import { repoFingerprint } from '../util';
import { smartTruncate } from '../utils/pr-body';
import * as helper from './gitea-helper';
import { giteaHttp } from './gitea-helper';
import { GiteaPrCache } from './pr-cache';
Expand Down Expand Up @@ -998,16 +997,21 @@ const platform: Platform = {
},

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

maxBodyLength,
maxCommentLength,
};

export function maxBodyLength(): number {
return 1000000;
}

export function maxCommentLength(): number {
return Infinity;
}

/* eslint-disable @typescript-eslint/unbound-method */
export const {
addAssignees,
Expand Down
12 changes: 12 additions & 0 deletions lib/modules/platform/github/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4203,4 +4203,16 @@ describe('modules/platform/github/index', () => {
expect(res).toBeNull();
});
});

describe('maxBodyLength()', () => {
it('returns 60000', () => {
expect(github.maxBodyLength()).toBe(60000);
});
});

describe('maxCommentLength()', () => {
it('returns Infinity', () => {
expect(github.maxCommentLength()).toBe(Infinity);
});
});
});
9 changes: 6 additions & 3 deletions lib/modules/platform/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import type {
} from '../types';
import { repoFingerprint } from '../util';
import { normalizeNamePerEcosystem } from '../utils/github-alerts';
import { smartTruncate } from '../utils/pr-body';
import { remoteBranchExists } from './branch';
import { coerceRestPr, githubApi } from './common';
import {
Expand Down Expand Up @@ -1941,7 +1940,7 @@ export async function mergePr({

export function massageMarkdown(input: string): string {
if (platformConfig.isGhe) {
return smartTruncate(input, maxBodyLength());
return input;
}
const massagedInput = massageMarkdownLinks(input)
// to be safe, replace all github.com links with redirect.github.com
Expand All @@ -1961,13 +1960,17 @@ export function massageMarkdown(input: string): string {
.replace('> ⚠ **Warning**\n> \n', '> [!WARNING]\n')
.replace('> ⚠️ **Warning**\n> \n', '> [!WARNING]\n')
.replace('> ❗ **Important**\n> \n', '> [!IMPORTANT]\n');
return smartTruncate(massagedInput, maxBodyLength());
return massagedInput;
}

export function maxBodyLength(): number {
return GitHubMaxPrBodyLen;
}

export function maxCommentLength(): number {
return Infinity;
}

export async function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> {
if (config.hasVulnerabilityAlertsEnabled === false) {
logger.debug('No vulnerability alerts enabled for repo');
Expand Down
26 changes: 12 additions & 14 deletions lib/modules/platform/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3068,25 +3068,23 @@ These updates have all been created already. Click a checkbox below to force a r
expect(gitlab.massageMarkdown(prBody)).toMatchSnapshot();
expect(smartTruncate).not.toHaveBeenCalled();
});
});

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

describe('maxBodyLength()', () => {
it('maxBodyLength is 25000 if too low API version', async () => {
await initFakePlatform('13.3.0');
gitlab.massageMarkdown(prBody);
expect(smartTruncate).toHaveBeenCalledTimes(1);
expect(smartTruncate).toHaveBeenCalledWith(expect.any(String), 25000);
expect(gitlab.maxBodyLength()).toBe(25000);
});

it('truncates description for API version gt 13.4', async () => {
jest.doMock('../utils/pr-body');
const { smartTruncate } = await import('../utils/pr-body');

it('maxBodyLength is 1000000 description for API version gt 13.4', async () => {
await initFakePlatform('13.4.1');
gitlab.massageMarkdown(prBody);
expect(smartTruncate).toHaveBeenCalledTimes(1);
expect(smartTruncate).toHaveBeenCalledWith(expect.any(String), 1000000);
expect(gitlab.maxBodyLength()).toBe(1000000);
});
});

describe('maxCommentLength()', () => {
it('returns Infinity', () => {
expect(gitlab.maxCommentLength()).toBe(Infinity);
});
});

Expand Down
7 changes: 5 additions & 2 deletions lib/modules/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import type {
UpdatePrConfig,
} from '../types';
import { repoFingerprint } from '../util';
import { smartTruncate } from '../utils/pr-body';
import {
getMemberUserIDs,
getMemberUsernames,
Expand Down Expand Up @@ -904,7 +903,7 @@ export function massageMarkdown(input: string): string {
.replace(regEx(/\]\(\.\.\/pull\//g), '](!')
// Strip unicode null characters as GitLab markdown does not permit them
.replace(regEx(/\u0000/g), ''); // eslint-disable-line no-control-regex
return smartTruncate(desc, maxBodyLength());
return desc;
}

export function maxBodyLength(): number {
Expand All @@ -919,6 +918,10 @@ export function maxBodyLength(): number {
}
}

export function maxCommentLength(): number {
return Infinity;
}

// Branch

function matchesState(state: string, desiredState: string): boolean {
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/platform/local/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ describe('modules/platform/local/index', () => {
expect(platform.maxBodyLength()).toBe(Infinity);
});

it('maxCommentLength', () => {
expect(platform.maxCommentLength()).toBe(Infinity);
});

it('updatePr', async () => {
expect(await platform.updatePr()).toBeUndefined();
});
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/platform/local/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export function maxBodyLength(): number {
return Infinity;
}

export function maxCommentLength(): number {
return Infinity;
}

export function updatePr(): Promise<void> {
return Promise.resolve();
}
Expand Down
Loading