diff --git a/lib/modules/platform/gerrit/client.spec.ts b/lib/modules/platform/gerrit/client.spec.ts index 8d64188c9f0fa3df546c2114a910832374613811..620ec9d5baef57cb54fff18c5e94a8ca161ca066 100644 --- a/lib/modules/platform/gerrit/client.spec.ts +++ b/lib/modules/platform/gerrit/client.spec.ts @@ -256,6 +256,18 @@ describe('modules/platform/gerrit/client', () => { .reply(200, gerritRestResponse([]), jsonResultHeader); await expect(client.addMessage(123456, 'message')).toResolve(); }); + + it('add too big message', async () => { + const okMessage = 'a'.repeat(0x4000); + const tooBigMessage = okMessage + 'b'; + httpMock + .scope(gerritEndpointUrl) + .post('/a/changes/123456/revisions/current/review', { + message: okMessage, + }) + .reply(200, gerritRestResponse([]), jsonResultHeader); + await expect(client.addMessage(123456, tooBigMessage)).toResolve(); + }); }); describe('checkForExistingMessage()', () => { diff --git a/lib/modules/platform/gerrit/client.ts b/lib/modules/platform/gerrit/client.ts index 4a5e3ccebab75c42507f99419559d0e41beac0f1..543328189ba7da37fffde1bfa53f8ca883bf8561 100644 --- a/lib/modules/platform/gerrit/client.ts +++ b/lib/modules/platform/gerrit/client.ts @@ -121,9 +121,10 @@ class GerritClient { async addMessage( changeNumber: number, - message: string, + fullMessage: string, tag?: string, ): Promise<void> { + const message = this.normalizeMessage(fullMessage); await this.gerritHttp.postJson( `a/changes/${changeNumber}/revisions/current/review`, { body: { message, tag } }, @@ -148,7 +149,7 @@ class GerritClient { message: string, tag?: string, ): Promise<void> { - const newMsg = message.trim(); //the last \n was removed from gerrit after the comment was added... + const newMsg = this.normalizeMessage(message); if (!(await this.checkForExistingMessage(changeNumber, newMsg, tag))) { await this.addMessage(changeNumber, newMsg, tag); } @@ -213,6 +214,11 @@ class GerritClient { ); } + normalizeMessage(message: string): string { + //the last \n was removed from gerrit after the comment was added... + return message.substring(0, 0x4000).trim(); + } + private static buildSearchFilters( repository: string, searchConfig: GerritFindPRConfig,