Skip to content

Commit

Permalink
fix(gitlab): Don't delete report_approver and code_owner approval…
Browse files Browse the repository at this point in the history
… rules (#27963)

Co-authored-by: Nikoms <nikom@gmail.com>
  • Loading branch information
Nikoms and Nikoms committed Mar 17, 2024
1 parent 481aa21 commit 92ab91b
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
78 changes: 78 additions & 0 deletions lib/modules/platform/gitlab/index.spec.ts
Expand Up @@ -2320,6 +2320,84 @@ describe('modules/platform/gitlab/index', () => {
});
});

it('does not try to remove "report_approver" and "code_owner" approval rules', 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')
.reply(200)
.get('/api/v4/projects/undefined/merge_requests/12345')
.reply(200, {
merge_status: 'can_be_merged',
pipeline: {
id: 29626725,
sha: '2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f',
ref: 'patch-28',
status: 'success',
},
})
.put('/api/v4/projects/undefined/merge_requests/12345/merge')
.reply(200)
.get('/api/v4/projects/undefined/merge_requests/12345/approval_rules')
.reply(200, [
{
name: 'RegularApproverRule',
rule_type: 'regular',
id: 50006,
},
{
name: 'AnotherRegularApproverRule',
rule_type: 'regular',
id: 50007,
},
{
name: 'Coverage-Check',
rule_type: 'report_approver',
id: 50008,
},
{
name: 'path/to/folder',
rule_type: 'code_owner',
id: 50009,
},
])
.delete(
'/api/v4/projects/undefined/merge_requests/12345/approval_rules/50006',
)
.reply(200)
.delete(
'/api/v4/projects/undefined/merge_requests/12345/approval_rules/50007',
)
.reply(200)
.post('/api/v4/projects/undefined/merge_requests/12345/approval_rules')
.reply(200);
expect(
await gitlab.createPr({
sourceBranch: 'some-branch',
targetBranch: 'master',
prTitle: 'some-title',
prBody: 'the-body',
labels: [],
platformOptions: {
usePlatformAutomerge: true,
gitLabIgnoreApprovals: true,
},
}),
).toStrictEqual({
id: 1,
iid: 12345,
number: 12345,
sourceBranch: 'some-branch',
title: 'some title',
});
});

it('does not try to create already existing approval rule', async () => {
await initPlatform('13.3.6-ee');
httpMock
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/platform/gitlab/index.ts
Expand Up @@ -608,7 +608,10 @@ async function ignoreApprovals(pr: number): Promise<void> {
);
const existingRegularApproverRules = rules?.filter(
({ rule_type, name }) =>
rule_type !== 'any_approver' && name !== ruleName,
rule_type !== 'any_approver' &&
name !== ruleName &&
rule_type !== 'report_approver' &&
rule_type !== 'code_owner',
);

if (existingRegularApproverRules?.length) {
Expand Down

0 comments on commit 92ab91b

Please sign in to comment.