Skip to content

Commit

Permalink
Merge branch 'main' into fix-auto-merge-if-plus-one
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs authored Nov 30, 2024
2 parents 6ac7b9e + 61eb99d commit 4817e82
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 90 deletions.
13 changes: 10 additions & 3 deletions lib/modules/platform/gerrit/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ describe('modules/platform/gerrit/client', () => {
.post('/a/changes/123456/revisions/current/review', {
message: 'message',
tag: 'tag',
notify: 'NONE',
})
.reply(200, gerritRestResponse([]), jsonResultHeader);
await expect(client.addMessage(123456, 'message', 'tag')).toResolve();
Expand All @@ -253,6 +254,7 @@ describe('modules/platform/gerrit/client', () => {
.scope(gerritEndpointUrl)
.post('/a/changes/123456/revisions/current/review', {
message: 'message',
notify: 'NONE',
})
.reply(200, gerritRestResponse([]), jsonResultHeader);
await expect(client.addMessage(123456, 'message')).toResolve();
Expand All @@ -265,6 +267,7 @@ describe('modules/platform/gerrit/client', () => {
.scope(gerritEndpointUrl)
.post('/a/changes/123456/revisions/current/review', {
message: okMessage,
notify: 'NONE',
})
.reply(200, gerritRestResponse([]), jsonResultHeader);
await expect(client.addMessage(123456, tooBigMessage)).toResolve();
Expand Down Expand Up @@ -311,6 +314,7 @@ describe('modules/platform/gerrit/client', () => {
.post('/a/changes/123456/revisions/current/review', {
message: 'new trimmed message',
tag: 'TAG',
notify: 'NONE',
})
.reply(200, gerritRestResponse([]), jsonResultHeader);

Expand Down Expand Up @@ -347,6 +351,7 @@ describe('modules/platform/gerrit/client', () => {
.scope(gerritEndpointUrl)
.post('/a/changes/123456/revisions/current/review', {
labels: { 'Code-Review': 2 },
notify: 'NONE',
})
.reply(200, gerritRestResponse([]), jsonResultHeader);
await expect(client.setLabel(123456, 'Code-Review', +2)).toResolve();
Expand All @@ -357,11 +362,12 @@ describe('modules/platform/gerrit/client', () => {
it('add', async () => {
httpMock
.scope(gerritEndpointUrl)
.post('/a/changes/123456/reviewers', {
reviewer: 'username',
.post('/a/changes/123456/revisions/current/review', {
reviewers: [{ reviewer: 'user1' }, { reviewer: 'user2' }],
notify: 'OWNER_REVIEWERS',
})
.reply(200, gerritRestResponse([]), jsonResultHeader);
await expect(client.addReviewer(123456, 'username')).toResolve();
await expect(client.addReviewers(123456, ['user1', 'user2'])).toResolve();
});
});

Expand Down Expand Up @@ -467,6 +473,7 @@ describe('modules/platform/gerrit/client', () => {
.scope(gerritEndpointUrl)
.post('/a/changes/123456/revisions/current/review', {
labels: { 'Code-Review': +2 },
notify: 'NONE',
})
.reply(200, gerritRestResponse(''), jsonResultHeader);
await expect(client.approveChange(123456)).toResolve();
Expand Down
19 changes: 13 additions & 6 deletions lib/modules/platform/gerrit/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class GerritClient {
const message = this.normalizeMessage(fullMessage);
await this.gerritHttp.postJson(
`a/changes/${changeNumber}/revisions/current/review`,
{ body: { message, tag } },
{ body: { message, tag, notify: 'NONE' } },
);
}

Expand Down Expand Up @@ -152,18 +152,25 @@ class GerritClient {
): Promise<void> {
await this.gerritHttp.postJson(
`a/changes/${changeNumber}/revisions/current/review`,
{ body: { labels: { [label]: value } } },
{ body: { labels: { [label]: value }, notify: 'NONE' } },
);
}

async addReviewer(changeNumber: number, reviewer: string): Promise<void> {
await this.gerritHttp.postJson(`a/changes/${changeNumber}/reviewers`, {
body: { reviewer },
});
async addReviewers(changeNumber: number, reviewers: string[]): Promise<void> {
await this.gerritHttp.postJson(
`a/changes/${changeNumber}/revisions/current/review`,
{
body: {
reviewers: reviewers.map((r) => ({ reviewer: r })),
notify: 'OWNER_REVIEWERS', // Avoids notifying cc's
},
},
);
}

async addAssignee(changeNumber: number, assignee: string): Promise<void> {
await this.gerritHttp.putJson<GerritAccountInfo>(
// TODO: refactor this as this API removed in Gerrit 3.8
`a/changes/${changeNumber}/assignee`,
{
body: { assignee },
Expand Down
12 changes: 3 additions & 9 deletions lib/modules/platform/gerrit/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,17 +610,11 @@ describe('modules/platform/gerrit/index', () => {
await expect(
gerrit.addReviewers(123456, ['user1', 'user2']),
).resolves.toBeUndefined();
expect(clientMock.addReviewer).toHaveBeenCalledTimes(2);
expect(clientMock.addReviewer).toHaveBeenNthCalledWith(
1,
123456,
expect(clientMock.addReviewers).toHaveBeenCalledTimes(1);
expect(clientMock.addReviewers).toHaveBeenCalledWith(123456, [
'user1',
);
expect(clientMock.addReviewer).toHaveBeenNthCalledWith(
2,
123456,
'user2',
);
]);
});
});

Expand Down
4 changes: 1 addition & 3 deletions lib/modules/platform/gerrit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@ export async function addReviewers(
number: number,
reviewers: string[],
): Promise<void> {
for (const reviewer of reviewers) {
await client.addReviewer(number, reviewer);
}
await client.addReviewers(number, reviewers);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/platform/gerrit/scm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ describe('modules/platform/gerrit/scm', () => {
expect(git.pushCommit).toHaveBeenCalledWith({
files: [],
sourceRef: 'renovate/dependency-1.x',
targetRef: 'refs/for/main',
targetRef: 'refs/for/main%notify=NONE',
});
});

Expand Down Expand Up @@ -403,7 +403,7 @@ describe('modules/platform/gerrit/scm', () => {
expect(git.pushCommit).toHaveBeenCalledWith({
files: [],
sourceRef: 'renovate/dependency-1.x',
targetRef: 'refs/for/main',
targetRef: 'refs/for/main%notify=NONE',
});
expect(clientMock.approveChange).toHaveBeenCalledWith(123456);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/gerrit/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class GerritScm extends DefaultGitScm {
if (hasChanges || commit.force) {
const pushResult = await git.pushCommit({
sourceRef: commit.branchName,
targetRef: `refs/for/${commit.baseBranch!}`,
targetRef: `refs/for/${commit.baseBranch!}%notify=NONE`,
files: commit.files,
});
if (pushResult) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
"@types/mdast": "3.0.15",
"@types/moo": "0.5.9",
"@types/ms": "0.7.34",
"@types/node": "20.17.6",
"@types/node": "20.17.7",
"@types/parse-link-header": "2.0.3",
"@types/punycode": "2.1.4",
"@types/semver": "7.5.8",
Expand Down
Loading

0 comments on commit 4817e82

Please sign in to comment.