Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gitlab): Add gitLabIgnoreApprovals option #10981

Merged
merged 18 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,13 @@ If you enabled `automerge` in the Renovate config, you can speed up the automerg
Caution (fixed in GitLab >= 12.7): when this option is enabled it is possible due to a bug in GitLab that MRs with failing pipelines might still get merged.
This is caused by a race condition in GitLab's Merge Request API - [read the corresponding issue](https://gitlab.com/gitlab-org/gitlab/issues/26293) for details.

## gitLabIgnoreApprovals

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

## golang

Configuration added here applies for all Go-related updates, however currently the only supported package manager for Go is the native Go Modules (the `gomod` manager).
Expand Down
8 changes: 7 additions & 1 deletion lib/config/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,13 @@ const options: RenovateOptions[] = [
},
{
name: 'gitLabAutomerge',
description: `Enable or disable usage of GitLab's "merge when pipeline succeeds" feature when automerging PRs.`,
description: `Enable or disable usage of GitLab's "merge when pipeline succeeds" feature when automerging MRs.`,
type: 'boolean',
default: false,
},
{
name: 'gitLabIgnoreApprovals',
description: `Ignore approval rules for MRs created by Renovate, which is useful for automerge.`,
type: 'boolean',
default: false,
},
Expand Down
292 changes: 292 additions & 0 deletions lib/platform/gitlab/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,108 @@ Array [
]
`;

exports[`platform/gitlab/index createPr(branchName, title, body) adds approval rule to ignore all approvals 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer some-token",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/user",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer some-token",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/version",
},
Object {
"body": "{\\"source_branch\\":\\"some-branch\\",\\"target_branch\\":\\"master\\",\\"remove_source_branch\\":true,\\"title\\":\\"some-title\\",\\"description\\":\\"the-body\\",\\"labels\\":\\"\\"}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"content-length": "142",
"content-type": "application/json",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "POST",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345/approval_rules",
},
Object {
"body": "{\\"name\\":\\"renovateIgnoreApprovals\\",\\"approvals_required\\":0}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"content-length": "57",
"content-type": "application/json",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "POST",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345/approval_rules",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345",
},
Object {
"body": "{\\"should_remove_source_branch\\":true,\\"merge_when_pipeline_succeeds\\":true}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"content-length": "72",
"content-type": "application/json",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "PUT",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345/merge",
},
]
`;

exports[`platform/gitlab/index createPr(branchName, title, body) auto-accepts the MR when requested 1`] = `
Array [
Object {
Expand Down Expand Up @@ -218,6 +320,94 @@ Array [
]
`;

exports[`platform/gitlab/index createPr(branchName, title, body) does not try to create already existing approval rule 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer some-token",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/user",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer some-token",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/version",
},
Object {
"body": "{\\"source_branch\\":\\"some-branch\\",\\"target_branch\\":\\"master\\",\\"remove_source_branch\\":true,\\"title\\":\\"some-title\\",\\"description\\":\\"the-body\\",\\"labels\\":\\"\\"}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"content-length": "142",
"content-type": "application/json",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "POST",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345/approval_rules",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345",
},
Object {
"body": "{\\"should_remove_source_branch\\":true,\\"merge_when_pipeline_succeeds\\":true}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"content-length": "72",
"content-type": "application/json",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "PUT",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345/merge",
},
]
`;

exports[`platform/gitlab/index createPr(branchName, title, body) returns the PR 1`] = `
Object {
"displayNumber": "Merge Request #12345",
Expand Down Expand Up @@ -270,6 +460,108 @@ Array [
]
`;

exports[`platform/gitlab/index createPr(branchName, title, body) silently ignores approval rules adding errors 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer some-token",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/user",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer some-token",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/version",
},
Object {
"body": "{\\"source_branch\\":\\"some-branch\\",\\"target_branch\\":\\"master\\",\\"remove_source_branch\\":true,\\"title\\":\\"some-title\\",\\"description\\":\\"the-body\\",\\"labels\\":\\"\\"}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"content-length": "142",
"content-type": "application/json",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "POST",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345/approval_rules",
},
Object {
"body": "{\\"name\\":\\"renovateIgnoreApprovals\\",\\"approvals_required\\":0}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"content-length": "57",
"content-type": "application/json",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "POST",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345/approval_rules",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "GET",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345",
},
Object {
"body": "{\\"should_remove_source_branch\\":true,\\"merge_when_pipeline_succeeds\\":true}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate, br",
"authorization": "Bearer abc123",
"content-length": "72",
"content-type": "application/json",
"host": "gitlab.com",
"user-agent": "RenovateBot/0.0.0-semantic-release (https://github.com/renovatebot/renovate)",
},
"method": "PUT",
"url": "https://gitlab.com/api/v4/projects/undefined/merge_requests/12345/merge",
},
]
`;

exports[`platform/gitlab/index createPr(branchName, title, body) supports draftPR on < 13.2 1`] = `
Object {
"displayNumber": "Merge Request #12345",
Expand Down
Loading