Skip to content

Commit d8ad99f

Browse files
authored
fix(platform/gerrit): Check for comment size limit (#26454)
1 parent b2422d8 commit d8ad99f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/modules/platform/gerrit/client.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ describe('modules/platform/gerrit/client', () => {
256256
.reply(200, gerritRestResponse([]), jsonResultHeader);
257257
await expect(client.addMessage(123456, 'message')).toResolve();
258258
});
259+
260+
it('add too big message', async () => {
261+
const okMessage = 'a'.repeat(0x4000);
262+
const tooBigMessage = okMessage + 'b';
263+
httpMock
264+
.scope(gerritEndpointUrl)
265+
.post('/a/changes/123456/revisions/current/review', {
266+
message: okMessage,
267+
})
268+
.reply(200, gerritRestResponse([]), jsonResultHeader);
269+
await expect(client.addMessage(123456, tooBigMessage)).toResolve();
270+
});
259271
});
260272

261273
describe('checkForExistingMessage()', () => {

lib/modules/platform/gerrit/client.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ class GerritClient {
121121

122122
async addMessage(
123123
changeNumber: number,
124-
message: string,
124+
fullMessage: string,
125125
tag?: string,
126126
): Promise<void> {
127+
const message = this.normalizeMessage(fullMessage);
127128
await this.gerritHttp.postJson(
128129
`a/changes/${changeNumber}/revisions/current/review`,
129130
{ body: { message, tag } },
@@ -148,7 +149,7 @@ class GerritClient {
148149
message: string,
149150
tag?: string,
150151
): Promise<void> {
151-
const newMsg = message.trim(); //the last \n was removed from gerrit after the comment was added...
152+
const newMsg = this.normalizeMessage(message);
152153
if (!(await this.checkForExistingMessage(changeNumber, newMsg, tag))) {
153154
await this.addMessage(changeNumber, newMsg, tag);
154155
}
@@ -213,6 +214,11 @@ class GerritClient {
213214
);
214215
}
215216

217+
normalizeMessage(message: string): string {
218+
//the last \n was removed from gerrit after the comment was added...
219+
return message.substring(0, 0x4000).trim();
220+
}
221+
216222
private static buildSearchFilters(
217223
repository: string,
218224
searchConfig: GerritFindPRConfig,

0 commit comments

Comments
 (0)