diff --git a/lib/modules/platform/azure/index.ts b/lib/modules/platform/azure/index.ts index 773a7e262272474fee3e79a384dd6f553c640886..f866e0dcdf2d983bd7d768b2b7546d8e5dbc7565 100644 --- a/lib/modules/platform/azure/index.ts +++ b/lib/modules/platform/azure/index.ts @@ -809,7 +809,7 @@ export async function mergePr({ export function massageMarkdown(input: string): string { // Remove any HTML we use - return smartTruncate(input, 4000) + return smartTruncate(input, maxBodyLength()) .replace( 'you tick the rebase/retry checkbox', 'rename PR to start with "rebase!"', @@ -822,6 +822,10 @@ export function massageMarkdown(input: string): string { .replace(regEx(/<!--renovate-(?:debug|config-hash):.*?-->/g), ''); } +export function maxBodyLength(): number { + return 4000; +} + /* istanbul ignore next */ export function findIssue(): Promise<Issue | null> { logger.warn(`findIssue() is not implemented`); diff --git a/lib/modules/platform/bitbucket-server/index.ts b/lib/modules/platform/bitbucket-server/index.ts index 1d0fb5f6078952f1b0945e27ce0aa2d5d0088b8b..caa5fc34b94efbb48bb9f67a8160c1f2f1b415bb 100644 --- a/lib/modules/platform/bitbucket-server/index.ts +++ b/lib/modules/platform/bitbucket-server/index.ts @@ -1068,7 +1068,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, 30000) + return smartTruncate(input, maxBodyLength()) .replace( 'you tick the rebase/retry checkbox', 'rename PR to start with "rebase!"', @@ -1082,3 +1082,7 @@ export function massageMarkdown(input: string): string { .replace(regEx(`\n---\n\n.*?<!-- rebase-check -->.*?(\n|$)`), '') .replace(regEx('<!--.*?-->', 'g'), ''); } + +export function maxBodyLength(): number { + return 30000; +} diff --git a/lib/modules/platform/bitbucket/index.ts b/lib/modules/platform/bitbucket/index.ts index bbd7bf997957a2acbd7959047b738649b78638df..b47fcd4421f2e59bf5d341803a7409c9013b2a91 100644 --- a/lib/modules/platform/bitbucket/index.ts +++ b/lib/modules/platform/bitbucket/index.ts @@ -570,7 +570,7 @@ async function closeIssue(issueNumber: number): Promise<void> { export function massageMarkdown(input: string): string { // Remove any HTML we use - return smartTruncate(input, 50000) + return smartTruncate(input, maxBodyLength()) .replace( 'you tick the rebase/retry checkbox', 'by renaming this PR to start with "rebase!"', @@ -586,6 +586,10 @@ export function massageMarkdown(input: string): string { .replace(regEx(/<!--renovate-(?:debug|config-hash):.*?-->/g), ''); } +export function maxBodyLength(): number { + return 50000; +} + export async function ensureIssue({ title, reuseTitle, diff --git a/lib/modules/platform/codecommit/index.spec.ts b/lib/modules/platform/codecommit/index.spec.ts index 487e09f12b278fffa38029bb98bc065f67e79166..e249c401b25c3f9329f5ab0342c10e0810b1c58b 100644 --- a/lib/modules/platform/codecommit/index.spec.ts +++ b/lib/modules/platform/codecommit/index.spec.ts @@ -63,6 +63,10 @@ describe('modules/platform/codecommit/index', () => { ); }); + it('maxBodyLength', () => { + expect(codeCommit.maxBodyLength()).toBe(Infinity); + }); + describe('initPlatform()', () => { it('should init', async () => { expect( diff --git a/lib/modules/platform/codecommit/index.ts b/lib/modules/platform/codecommit/index.ts index 741eb18a5eaec59066fb65c8df40ea108e21b325..35c49684caf46cc4b092d058ef6392b54baf6631 100644 --- a/lib/modules/platform/codecommit/index.ts +++ b/lib/modules/platform/codecommit/index.ts @@ -322,6 +322,13 @@ export function massageMarkdown(input: string): string { ); } +/** + * Unsed, no Dashboard + */ +export function maxBodyLength(): number { + return Infinity; +} + export async function getJsonFile( fileName: string, repoName?: string, diff --git a/lib/modules/platform/gerrit/index.ts b/lib/modules/platform/gerrit/index.ts index ddd058f21e11d2b8a2a2fa713c14b2007130db2f..db740964fe60c9567c557024f89b6ff8ef65e691 100644 --- a/lib/modules/platform/gerrit/index.ts +++ b/lib/modules/platform/gerrit/index.ts @@ -396,7 +396,7 @@ export async function ensureComment( export function massageMarkdown(prBody: string): string { //TODO: do more Gerrit specific replacements? - return smartTruncate(readOnlyIssueBody(prBody), 16384) //TODO: check the real gerrit limit (max. chars) + return smartTruncate(readOnlyIssueBody(prBody), maxBodyLength()) .replace(regEx(/Pull Request(s)?/g), 'Change-Request$1') .replace(regEx(/\bPR(s)?\b/g), 'Change-Request$1') .replace(regEx(/<\/?summary>/g), '**') @@ -419,6 +419,10 @@ export function massageMarkdown(prBody: string): string { .replace(regEx(/<!--renovate-(?:debug|config-hash):.*?-->/g), ''); } +export function maxBodyLength(): number { + return 16384; //TODO: check the real gerrit limit (max. chars) +} + export function deleteLabel(number: number, label: string): Promise<void> { return Promise.resolve(); } diff --git a/lib/modules/platform/gitea/index.spec.ts b/lib/modules/platform/gitea/index.spec.ts index f74c4270c156068e6186550c00365c5cb51c2944..61141ec63cb9f26e4ed9c5442aecf5cf9bf8bd51 100644 --- a/lib/modules/platform/gitea/index.spec.ts +++ b/lib/modules/platform/gitea/index.spec.ts @@ -2834,6 +2834,10 @@ describe('modules/platform/gitea/index', () => { }); }); + it('maxBodyLength', () => { + expect(gitea.maxBodyLength()).toBe(1000000); + }); + describe('getJsonFile()', () => { it('returns file content', async () => { const data = { foo: 'bar' }; diff --git a/lib/modules/platform/gitea/index.ts b/lib/modules/platform/gitea/index.ts index b4859dfe99c140b61682aac854494cb593b3578b..04232733965fe1295f76845a8cf0141c2b18143c 100644 --- a/lib/modules/platform/gitea/index.ts +++ b/lib/modules/platform/gitea/index.ts @@ -1001,10 +1001,16 @@ const platform: Platform = { }, massageMarkdown(prBody: string): string { - return smartTruncate(smartLinks(prBody), 1000000); + return smartTruncate(smartLinks(prBody), maxBodyLength()); }, + + maxBodyLength, }; +export function maxBodyLength(): number { + return 1000000; +} + /* eslint-disable @typescript-eslint/unbound-method */ export const { addAssignees, diff --git a/lib/modules/platform/github/index.ts b/lib/modules/platform/github/index.ts index 764e6fe33f36a7224b7935f0947a35860a4e1827..a3457a0253869e7467b83f271e55dc533ef706d0 100644 --- a/lib/modules/platform/github/index.ts +++ b/lib/modules/platform/github/index.ts @@ -96,7 +96,7 @@ export const id = 'github'; let config: LocalRepoConfig; let platformConfig: PlatformConfig; -export const GitHubMaxPrBodyLen = 60000; +const GitHubMaxPrBodyLen = 60000; export function resetConfigs(): void { config = {} as never; @@ -1938,7 +1938,7 @@ export async function mergePr({ export function massageMarkdown(input: string): string { if (platformConfig.isGhe) { - return smartTruncate(input, GitHubMaxPrBodyLen); + return smartTruncate(input, maxBodyLength()); } const massagedInput = massageMarkdownLinks(input) // to be safe, replace all github.com links with renovatebot redirector @@ -1952,7 +1952,11 @@ 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, GitHubMaxPrBodyLen); + return smartTruncate(massagedInput, maxBodyLength()); +} + +export function maxBodyLength(): number { + return GitHubMaxPrBodyLen; } export async function getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]> { diff --git a/lib/modules/platform/gitlab/index.ts b/lib/modules/platform/gitlab/index.ts index 4a28db74a02aeecfdcaf211d1e657fce542797b4..4fb612ee4e31975887bf1f8e99537f76d805daf4 100644 --- a/lib/modules/platform/gitlab/index.ts +++ b/lib/modules/platform/gitlab/index.ts @@ -897,26 +897,26 @@ export async function mergePr({ id }: MergePRConfig): Promise<boolean> { } export function massageMarkdown(input: string): string { - let desc = input + const desc = input .replace(regEx(/Pull Request/g), 'Merge Request') .replace(regEx(/\bPR\b/g), 'MR') .replace(regEx(/\bPRs\b/g), 'MRs') .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()); +} +export function maxBodyLength(): number { if (semver.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 25000; } else { - desc = smartTruncate(desc, 1000000); + return 1000000; } - - return desc; } // Branch diff --git a/lib/modules/platform/local/index.spec.ts b/lib/modules/platform/local/index.spec.ts index dbb631d469575191628a2db8482f0681f2a60124..140f38ec6f509dbbbd4dc08d17427bf4150a76be 100644 --- a/lib/modules/platform/local/index.spec.ts +++ b/lib/modules/platform/local/index.spec.ts @@ -65,6 +65,10 @@ describe('modules/platform/local/index', () => { expect(platform.massageMarkdown('foo')).toBe('foo'); }); + it('maxBodyLength', () => { + expect(platform.maxBodyLength()).toBe(Infinity); + }); + it('updatePr', async () => { expect(await platform.updatePr()).toBeUndefined(); }); diff --git a/lib/modules/platform/local/index.ts b/lib/modules/platform/local/index.ts index 186460ab2ede8a1f6c9c34c66d7a5fbdbe3c4d7a..c3646ebb4f82413e619688c0161878981267a87a 100644 --- a/lib/modules/platform/local/index.ts +++ b/lib/modules/platform/local/index.ts @@ -62,6 +62,13 @@ export function massageMarkdown(input: string): string { return input; } +/** + * Unsed, no Dashboard + */ +export function maxBodyLength(): number { + return Infinity; +} + export function updatePr(): Promise<void> { return Promise.resolve(); } diff --git a/lib/modules/platform/types.ts b/lib/modules/platform/types.ts index 28f622cd61a33c96b7d26a5c5411311f2cf8992e..e9f21232d71b4a82f7f41c828a8125b5a58cc38c 100644 --- a/lib/modules/platform/types.ts +++ b/lib/modules/platform/types.ts @@ -277,6 +277,8 @@ export interface Platform { filterUnavailableUsers?(users: string[]): Promise<string[]>; commitFiles?(config: CommitFilesConfig): Promise<LongCommitSha | null>; expandGroupMembers?(reviewersOrAssignees: string[]): Promise<string[]>; + + maxBodyLength(): number; } export interface PlatformScm { diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts index d82ab52dd9443ce6fd439259a46fa0dcd0680f2c..63f0b79cea660a8a11aedb76ce68259190f92813 100644 --- a/lib/workers/repository/dependency-dashboard.spec.ts +++ b/lib/workers/repository/dependency-dashboard.spec.ts @@ -15,10 +15,7 @@ import type { PackageFile, } from '../../modules/manager/types'; import type { Platform } from '../../modules/platform'; -import { - GitHubMaxPrBodyLen, - massageMarkdown, -} from '../../modules/platform/github'; +import { massageMarkdown } from '../../modules/platform/github'; import { clone } from '../../util/clone'; import { regEx } from '../../util/regex'; import type { BranchConfig, BranchUpgradeConfig } from '../types'; @@ -47,6 +44,7 @@ let config: RenovateConfig; beforeEach(() => { massageMdSpy.mockImplementation(massageMarkdown); + platform.maxBodyLength.mockReturnValue(60000); // Github Limit config = getConfig(); config.platform = 'github'; config.errors = []; @@ -1063,7 +1061,7 @@ None detected expect(platform.ensureIssue).toHaveBeenCalledTimes(1); expect( platform.ensureIssue.mock.calls[0][0].body.length < - GitHubMaxPrBodyLen, + platform.maxBodyLength(), ).toBeTrue(); // same with dry run diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index a1233d68518c77a6aeaeaced2bf179896c64dc08..d23e5e70beb2980965fda91b69b404bd10ad332f 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -4,7 +4,6 @@ import type { RenovateConfig } from '../../config/types'; import { logger } from '../../logger'; import type { PackageFile } from '../../modules/manager/types'; import { platform } from '../../modules/platform'; -import { GitHubMaxPrBodyLen } from '../../modules/platform/github'; import { regEx } from '../../util/regex'; import { coerceString } from '../../util/string'; import * as template from '../../util/template'; @@ -468,7 +467,7 @@ export async function ensureDependencyDashboard( // fit the detected dependencies section const footer = getFooter(config); issueBody += PackageFiles.getDashboardMarkdown( - GitHubMaxPrBodyLen - issueBody.length - footer.length, + platform.maxBodyLength() - issueBody.length - footer.length, ); issueBody += footer;