diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index 125bccf0971000d763f83f6d72cf452cfb0a0667..09dc38bc540f13ee708c1333f8cd64f9c590aa9f 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -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 diff --git a/lib/modules/platform/gitlab/index.spec.ts b/lib/modules/platform/gitlab/index.spec.ts index 3878f49d6229f167ff387999bad54632f24d8fb0..f327ec9a5d4ec920bca09d822f6d66cf1e58f1c8 100644 --- a/lib/modules/platform/gitlab/index.spec.ts +++ b/lib/modules/platform/gitlab/index.spec.ts @@ -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 diff --git a/lib/modules/platform/gitlab/index.ts b/lib/modules/platform/gitlab/index.ts index 90eccc206c9640e10b010704f96fd40d2edbea0d..4a28db74a02aeecfdcaf211d1e657fce542797b4 100644 --- a/lib/modules/platform/gitlab/index.ts +++ b/lib/modules/platform/gitlab/index.ts @@ -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', @@ -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'); } }