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

fix(gitlab): remove approval rules only if automerging #31720

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
38 changes: 38 additions & 0 deletions lib/config/presets/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,44 @@
});
expect(content).toEqual({ foo: 'bar' });
});

it('should remove approval rules for merge requests with automerge enabled', async () => {
httpMock
.scope(gitlabApiHost)
.get(projectPath)
.reply(200, {
default_branch: 'main',
})
.get(`${basePath}/files/default.json/raw?ref=main`)
.reply(200, { foo: 'bar' }, {});

const content = await gitlab.getPreset({ repo: 'some/repo' });
expect(content).toEqual({ foo: 'bar' });

// Simulate automerge enabled
const automergeEnabled = true;
const approvalRulesRemoved = await gitlab.tryPrAutomerge(1, { gitLabIgnoreApprovals: true }, automergeEnabled);

Check failure on line 143 in lib/config/presets/gitlab/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'tryPrAutomerge' not found in imported namespace 'gitlab'.
expect(approvalRulesRemoved).toBe(true);
});

it('should not remove approval rules for merge requests without automerge enabled', async () => {
httpMock
.scope(gitlabApiHost)
.get(projectPath)
.reply(200, {
default_branch: 'main',
})
.get(`${basePath}/files/default.json/raw?ref=main`)
.reply(200, { foo: 'bar' }, {});

const content = await gitlab.getPreset({ repo: 'some/repo' });
expect(content).toEqual({ foo: 'bar' });

// Simulate automerge disabled
const automergeDisabled = false;
const approvalRulesRemoved = await gitlab.tryPrAutomerge(1, { gitLabIgnoreApprovals: true }, automergeDisabled);

Check failure on line 162 in lib/config/presets/gitlab/index.spec.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'tryPrAutomerge' not found in imported namespace 'gitlab'.
expect(approvalRulesRemoved).toBe(false);
});
rarkins marked this conversation as resolved.
Show resolved Hide resolved
});

describe('getPresetFromEndpoint()', () => {
Expand Down
13 changes: 8 additions & 5 deletions lib/modules/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,6 @@
platformPrOptions: PlatformPrOptions | undefined,
): Promise<void> {
try {
if (platformPrOptions?.gitLabIgnoreApprovals) {
await ignoreApprovals(pr);
}

if (platformPrOptions?.usePlatformAutomerge) {
// https://docs.gitlab.com/ee/api/merge_requests.html#merge-status
const desiredDetailedMergeStatus = [
Expand Down Expand Up @@ -757,6 +753,7 @@
draftPR,
labels,
platformPrOptions,
automerge,

Check failure on line 756 in lib/modules/platform/gitlab/index.ts

View workflow job for this annotation

GitHub Actions / build

Property 'automerge' does not exist on type 'CreatePRConfig'.
}: CreatePRConfig): Promise<Pr> {
let title = prTitle;
if (draftPR) {
Expand Down Expand Up @@ -790,7 +787,13 @@
await approvePr(pr.iid);
}

await tryPrAutomerge(pr.iid, platformPrOptions);
if (platformPrOptions?.gitLabIgnoreApprovals && automerge) {
await ignoreApprovals(pr.iid);
}

if (automerge) {
await tryPrAutomerge(pr.iid, platformPrOptions);
}

return massagePr(pr);
}
Expand Down
Loading