Skip to content

Commit

Permalink
fix(config): Remove usePlatformAutomerge restriction with gitLabIgnor…
Browse files Browse the repository at this point in the history
…eApprovals (#29972)
  • Loading branch information
aav7fl committed Jul 1, 2024
1 parent 67ad98c commit d0e0bbe
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ Example:

Ignore the default project level approval(s), so that Renovate bot can automerge its merge requests, without needing approval(s).
Under the hood, it creates a MR-level approval rule where `approvals_required` is set to `0`.
This option works only when `automerge=true`, `automergeType=pr` or `automergeType=branch`, and `platformAutomerge=true`.
This option works only when `automerge=true` and either `automergeType=pr` or `automergeType=branch`.
Also, approval rules overriding should not be [prevented in GitLab settings](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/settings.html#prevent-editing-approval-rules-in-merge-requests).

## goGetDirs
Expand Down
43 changes: 43 additions & 0 deletions lib/modules/platform/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,49 @@ describe('modules/platform/gitlab/index', () => {
`);
});

it('adds approval rule to ignore all approvals when platformAutomerge is false', async () => {
await initPlatform('13.3.6-ee');
httpMock
.scope(gitlabApiHost)
.post('/api/v4/projects/undefined/merge_requests')
.reply(200, {
id: 1,
iid: 12345,
title: 'some title',
})
.get('/api/v4/projects/undefined/merge_requests/12345/approval_rules')
.reply(200, [
{
name: 'AnyApproverRule',
rule_type: 'any_approver',
id: 50005,
},
])
.put(
'/api/v4/projects/undefined/merge_requests/12345/approval_rules/50005',
)
.reply(200);
expect(
await gitlab.createPr({
sourceBranch: 'some-branch',
targetBranch: 'master',
prTitle: 'some-title',
prBody: 'the-body',
labels: [],
platformOptions: {
usePlatformAutomerge: false,
gitLabIgnoreApprovals: true,
},
}),
).toEqual({
id: 1,
iid: 12345,
number: 12345,
sourceBranch: 'some-branch',
title: 'some title',
});
});

it('will modify a rule of type any_approvers, if such a rule exists', async () => {
await initPlatform('13.3.6-ee');
httpMock
Expand Down
14 changes: 7 additions & 7 deletions lib/modules/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,12 @@ async function tryPrAutomerge(
pr: number,
platformOptions: PlatformPrOptions | undefined,
): Promise<void> {
if (platformOptions?.usePlatformAutomerge) {
try {
if (platformOptions?.gitLabIgnoreApprovals) {
await ignoreApprovals(pr);
}
try {
if (platformOptions?.gitLabIgnoreApprovals) {
await ignoreApprovals(pr);
}

if (platformOptions?.usePlatformAutomerge) {
// https://docs.gitlab.com/ee/api/merge_requests.html#merge-status
const desiredDetailedMergeStatus = [
'mergeable',
Expand Down Expand Up @@ -730,9 +730,9 @@ async function tryPrAutomerge(
}
await setTimeout(mergeDelay * attempt ** 2); // exponential backoff
}
} catch (err) /* istanbul ignore next */ {
logger.debug({ err }, 'Automerge on PR creation failed');
}
} catch (err) /* istanbul ignore next */ {
logger.debug({ err }, 'Automerge on PR creation failed');
}
}

Expand Down

0 comments on commit d0e0bbe

Please sign in to comment.