mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-09 21:46:26 +00:00
Revert "feat(gitlab,azure): try approving before auto-merge"
This reverts commit c679c28d01
.
This commit is contained in:
parent
539c12f744
commit
7923d5b955
6 changed files with 38 additions and 272 deletions
|
@ -217,10 +217,6 @@ exports[`modules/platform/azure/index updatePr(prNo, title, body, platformPrOpti
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`modules/platform/azure/index updatePr(prNo, title, body, platformPrOptions) should not re-approve if the PR is already approved 1`] = `undefined`;
|
|
||||||
|
|
||||||
exports[`modules/platform/azure/index updatePr(prNo, title, body, platformPrOptions) should re-approve if the PR was approved by another user 1`] = `undefined`;
|
|
||||||
|
|
||||||
exports[`modules/platform/azure/index updatePr(prNo, title, body, platformPrOptions) should re-approve the PR 1`] = `undefined`;
|
exports[`modules/platform/azure/index updatePr(prNo, title, body, platformPrOptions) should re-approve the PR 1`] = `undefined`;
|
||||||
|
|
||||||
exports[`modules/platform/azure/index updatePr(prNo, title, body, platformPrOptions) should reopen the PR 1`] = `
|
exports[`modules/platform/azure/index updatePr(prNo, title, body, platformPrOptions) should reopen the PR 1`] = `
|
||||||
|
|
|
@ -1149,7 +1149,7 @@ describe('modules/platform/azure/index', () => {
|
||||||
const updateFn = jest
|
const updateFn = jest
|
||||||
.fn(() => prUpdateResult)
|
.fn(() => prUpdateResult)
|
||||||
.mockName('createPullRequestReviewer');
|
.mockName('createPullRequestReviewer');
|
||||||
azureApi.gitApi.mockImplementation(
|
azureApi.gitApi.mockImplementationOnce(
|
||||||
() =>
|
() =>
|
||||||
({
|
({
|
||||||
createPullRequest: jest.fn(() => prResult),
|
createPullRequest: jest.fn(() => prResult),
|
||||||
|
@ -1293,7 +1293,7 @@ describe('modules/platform/azure/index', () => {
|
||||||
isRequired: false,
|
isRequired: false,
|
||||||
};
|
};
|
||||||
const updateFn = jest.fn(() => prUpdateResult);
|
const updateFn = jest.fn(() => prUpdateResult);
|
||||||
azureApi.gitApi.mockImplementation(
|
azureApi.gitApi.mockImplementationOnce(
|
||||||
() =>
|
() =>
|
||||||
({
|
({
|
||||||
updatePullRequest: jest.fn(() => prResult),
|
updatePullRequest: jest.fn(() => prResult),
|
||||||
|
@ -1313,82 +1313,6 @@ describe('modules/platform/azure/index', () => {
|
||||||
expect(updateFn).toHaveBeenCalled();
|
expect(updateFn).toHaveBeenCalled();
|
||||||
expect(pr).toMatchSnapshot();
|
expect(pr).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not re-approve if the PR is already approved', async () => {
|
|
||||||
await initRepo({ repository: 'some/repo' });
|
|
||||||
const prResult = {
|
|
||||||
pullRequestId: 456,
|
|
||||||
createdBy: {
|
|
||||||
id: 123,
|
|
||||||
url: 'user-url',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const prUpdateResult = {
|
|
||||||
reviewerUrl: prResult.createdBy.url,
|
|
||||||
vote: AzurePrVote.Approved,
|
|
||||||
isFlagged: false,
|
|
||||||
isRequired: false,
|
|
||||||
};
|
|
||||||
const updateFn = jest.fn(() => prUpdateResult);
|
|
||||||
azureApi.gitApi.mockImplementation(
|
|
||||||
() =>
|
|
||||||
({
|
|
||||||
updatePullRequest: jest.fn(() => prResult),
|
|
||||||
createPullRequestReviewer: updateFn,
|
|
||||||
getPullRequestById: jest.fn(() => ({
|
|
||||||
pullRequestId: prResult.pullRequestId,
|
|
||||||
createdBy: prResult.createdBy,
|
|
||||||
reviewers: [{ vote: AzurePrVote.Approved, id: 123 }],
|
|
||||||
})),
|
|
||||||
}) as any,
|
|
||||||
);
|
|
||||||
const pr = await azure.updatePr({
|
|
||||||
number: prResult.pullRequestId,
|
|
||||||
prTitle: 'The Title',
|
|
||||||
prBody: 'Hello world',
|
|
||||||
platformPrOptions: { autoApprove: true },
|
|
||||||
});
|
|
||||||
expect(updateFn).not.toHaveBeenCalled();
|
|
||||||
expect(pr).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should re-approve if the PR was approved by another user', async () => {
|
|
||||||
await initRepo({ repository: 'some/repo' });
|
|
||||||
const prResult = {
|
|
||||||
pullRequestId: 456,
|
|
||||||
createdBy: {
|
|
||||||
id: 123,
|
|
||||||
url: 'user-url',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const prUpdateResult = {
|
|
||||||
reviewerUrl: prResult.createdBy.url,
|
|
||||||
vote: AzurePrVote.Approved,
|
|
||||||
isFlagged: false,
|
|
||||||
isRequired: false,
|
|
||||||
};
|
|
||||||
const updateFn = jest.fn(() => prUpdateResult);
|
|
||||||
azureApi.gitApi.mockImplementation(
|
|
||||||
() =>
|
|
||||||
({
|
|
||||||
updatePullRequest: jest.fn(() => prResult),
|
|
||||||
createPullRequestReviewer: updateFn,
|
|
||||||
getPullRequestById: jest.fn(() => ({
|
|
||||||
pullRequestId: prResult.pullRequestId,
|
|
||||||
createdBy: prResult.createdBy,
|
|
||||||
reviewers: [{ vote: AzurePrVote.Approved, id: 321 }],
|
|
||||||
})),
|
|
||||||
}) as any,
|
|
||||||
);
|
|
||||||
const pr = await azure.updatePr({
|
|
||||||
number: prResult.pullRequestId,
|
|
||||||
prTitle: 'The Title',
|
|
||||||
prBody: 'Hello world',
|
|
||||||
platformPrOptions: { autoApprove: true },
|
|
||||||
});
|
|
||||||
expect(updateFn).toHaveBeenCalled();
|
|
||||||
expect(pr).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ensureComment', () => {
|
describe('ensureComment', () => {
|
||||||
|
|
|
@ -513,7 +513,18 @@ export async function createPr({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (platformPrOptions?.autoApprove) {
|
if (platformPrOptions?.autoApprove) {
|
||||||
await approvePr(pr);
|
await azureApiGit.createPullRequestReviewer(
|
||||||
|
{
|
||||||
|
reviewerUrl: pr.createdBy!.url,
|
||||||
|
vote: AzurePrVote.Approved,
|
||||||
|
isFlagged: false,
|
||||||
|
isRequired: false,
|
||||||
|
},
|
||||||
|
config.repoId,
|
||||||
|
// TODO #22198
|
||||||
|
pr.pullRequestId!,
|
||||||
|
pr.createdBy!.id!,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
labels!.map((label) =>
|
labels!.map((label) =>
|
||||||
|
@ -570,7 +581,19 @@ export async function updatePr({
|
||||||
objToUpdate.status = PullRequestStatus.Abandoned;
|
objToUpdate.status = PullRequestStatus.Abandoned;
|
||||||
}
|
}
|
||||||
if (platformPrOptions?.autoApprove) {
|
if (platformPrOptions?.autoApprove) {
|
||||||
await approvePr(prNo);
|
const pr = await azureApiGit.getPullRequestById(prNo, config.project);
|
||||||
|
await azureApiGit.createPullRequestReviewer(
|
||||||
|
{
|
||||||
|
reviewerUrl: pr.createdBy!.url,
|
||||||
|
vote: AzurePrVote.Approved,
|
||||||
|
isFlagged: false,
|
||||||
|
isRequired: false,
|
||||||
|
},
|
||||||
|
config.repoId,
|
||||||
|
// TODO #22198
|
||||||
|
pr.pullRequestId!,
|
||||||
|
pr.createdBy!.id!,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedPr = await azureApiGit.updatePullRequest(
|
const updatedPr = await azureApiGit.updatePullRequest(
|
||||||
|
@ -992,37 +1015,3 @@ export async function deleteLabel(
|
||||||
const azureApiGit = await azureApi.gitApi();
|
const azureApiGit = await azureApi.gitApi();
|
||||||
await azureApiGit.deletePullRequestLabels(config.repoId, prNumber, label);
|
await azureApiGit.deletePullRequestLabels(config.repoId, prNumber, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function approvePr(
|
|
||||||
prNumberOrPr: number | GitPullRequest,
|
|
||||||
): Promise<void> {
|
|
||||||
const azureApiGit = await azureApi.gitApi();
|
|
||||||
const pr =
|
|
||||||
typeof prNumberOrPr === 'number'
|
|
||||||
? await azureApiGit.getPullRequestById(prNumberOrPr, config.project)
|
|
||||||
: prNumberOrPr;
|
|
||||||
|
|
||||||
const isApproved = pr.reviewers?.some(
|
|
||||||
(reviewer) =>
|
|
||||||
reviewer.vote === AzurePrVote.Approved &&
|
|
||||||
reviewer.id === pr.createdBy?.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isApproved) {
|
|
||||||
logger.debug('PR is already approved');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await azureApiGit.createPullRequestReviewer(
|
|
||||||
{
|
|
||||||
reviewerUrl: pr.createdBy!.url,
|
|
||||||
vote: AzurePrVote.Approved,
|
|
||||||
isFlagged: false,
|
|
||||||
isRequired: false,
|
|
||||||
},
|
|
||||||
config.repoId,
|
|
||||||
// TODO #22198
|
|
||||||
pr.pullRequestId!,
|
|
||||||
pr.createdBy!.id!,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
@ -128,18 +128,9 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should reuse existing gitAuthor`, async () => {
|
it(`should reuse existing gitAuthor`, async () => {
|
||||||
httpMock
|
httpMock.scope(gitlabApiHost).get('/api/v4/version').reply(200, {
|
||||||
.scope(gitlabApiHost)
|
version: '13.3.6-ee',
|
||||||
.get('/api/v4/user')
|
});
|
||||||
.reply(200, {
|
|
||||||
email: 'different@email.com',
|
|
||||||
name: 'Different Name',
|
|
||||||
id: 1,
|
|
||||||
})
|
|
||||||
.get('/api/v4/version')
|
|
||||||
.reply(200, {
|
|
||||||
version: '13.3.6-ee',
|
|
||||||
});
|
|
||||||
expect(
|
expect(
|
||||||
await gitlab.initPlatform({
|
await gitlab.initPlatform({
|
||||||
token: 'some-token',
|
token: 'some-token',
|
||||||
|
@ -1909,7 +1900,6 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
.get('/api/v4/user')
|
.get('/api/v4/user')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
email: 'a@b.com',
|
email: 'a@b.com',
|
||||||
id: 1,
|
|
||||||
name: 'Renovate Bot',
|
name: 'Renovate Bot',
|
||||||
})
|
})
|
||||||
.get('/api/v4/version')
|
.get('/api/v4/version')
|
||||||
|
@ -2788,10 +2778,6 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
target_branch: 'master',
|
target_branch: 'master',
|
||||||
description: 'the-body',
|
description: 'the-body',
|
||||||
})
|
})
|
||||||
.get('/api/v4/projects/undefined/merge_requests/12345/approvals')
|
|
||||||
.reply(200, {
|
|
||||||
approved_by: [],
|
|
||||||
})
|
|
||||||
.post('/api/v4/projects/undefined/merge_requests/12345/approve')
|
.post('/api/v4/projects/undefined/merge_requests/12345/approve')
|
||||||
.reply(200);
|
.reply(200);
|
||||||
expect(
|
expect(
|
||||||
|
@ -2825,8 +2811,6 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
target_branch: 'master',
|
target_branch: 'master',
|
||||||
description: 'the-body',
|
description: 'the-body',
|
||||||
})
|
})
|
||||||
.get('/api/v4/projects/undefined/merge_requests/12345/approvals')
|
|
||||||
.replyWithError('some error')
|
|
||||||
.post('/api/v4/projects/undefined/merge_requests/12345/approve')
|
.post('/api/v4/projects/undefined/merge_requests/12345/approve')
|
||||||
.replyWithError('some error');
|
.replyWithError('some error');
|
||||||
await expect(
|
await expect(
|
||||||
|
@ -3155,104 +3139,6 @@ describe('modules/platform/gitlab/index', () => {
|
||||||
description: 'body',
|
description: 'body',
|
||||||
state: 'opened',
|
state: 'opened',
|
||||||
})
|
})
|
||||||
.get('/api/v4/projects/undefined/merge_requests/1/approvals')
|
|
||||||
.reply(200, {
|
|
||||||
approved_by: [],
|
|
||||||
})
|
|
||||||
.post('/api/v4/projects/undefined/merge_requests/1/approve')
|
|
||||||
.reply(200);
|
|
||||||
await expect(
|
|
||||||
gitlab.updatePr({
|
|
||||||
number: 1,
|
|
||||||
prTitle: 'title',
|
|
||||||
prBody: 'body',
|
|
||||||
platformPrOptions: {
|
|
||||||
autoApprove: true,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
).toResolve();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not auto-approve if already approved', async () => {
|
|
||||||
await initPlatform('13.3.6-ee');
|
|
||||||
httpMock
|
|
||||||
.scope(gitlabApiHost)
|
|
||||||
.get(
|
|
||||||
'/api/v4/projects/undefined/merge_requests?per_page=100&scope=created_by_me',
|
|
||||||
)
|
|
||||||
.reply(200, [
|
|
||||||
{
|
|
||||||
iid: 1,
|
|
||||||
source_branch: 'branch-a',
|
|
||||||
title: 'branch a pr',
|
|
||||||
description: 'a merge request',
|
|
||||||
state: 'opened',
|
|
||||||
},
|
|
||||||
])
|
|
||||||
.put('/api/v4/projects/undefined/merge_requests/1')
|
|
||||||
.reply(200, {
|
|
||||||
iid: 1,
|
|
||||||
source_branch: 'branch-a',
|
|
||||||
title: 'title',
|
|
||||||
description: 'body',
|
|
||||||
state: 'opened',
|
|
||||||
})
|
|
||||||
.get('/api/v4/projects/undefined/merge_requests/1/approvals')
|
|
||||||
.reply(200, {
|
|
||||||
approved_by: [
|
|
||||||
{
|
|
||||||
user: {
|
|
||||||
id: 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
await expect(
|
|
||||||
gitlab.updatePr({
|
|
||||||
number: 1,
|
|
||||||
prTitle: 'title',
|
|
||||||
prBody: 'body',
|
|
||||||
platformPrOptions: {
|
|
||||||
autoApprove: true,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
).toResolve();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('auto-approves if approved by another user', async () => {
|
|
||||||
await initPlatform('13.3.6-ee');
|
|
||||||
httpMock
|
|
||||||
.scope(gitlabApiHost)
|
|
||||||
.get(
|
|
||||||
'/api/v4/projects/undefined/merge_requests?per_page=100&scope=created_by_me',
|
|
||||||
)
|
|
||||||
.reply(200, [
|
|
||||||
{
|
|
||||||
iid: 1,
|
|
||||||
source_branch: 'branch-a',
|
|
||||||
title: 'branch a pr',
|
|
||||||
description: 'a merge request',
|
|
||||||
state: 'opened',
|
|
||||||
},
|
|
||||||
])
|
|
||||||
.put('/api/v4/projects/undefined/merge_requests/1')
|
|
||||||
.reply(200, {
|
|
||||||
iid: 1,
|
|
||||||
source_branch: 'branch-a',
|
|
||||||
title: 'title',
|
|
||||||
description: 'body',
|
|
||||||
state: 'opened',
|
|
||||||
})
|
|
||||||
.get('/api/v4/projects/undefined/merge_requests/1/approvals')
|
|
||||||
.reply(200, {
|
|
||||||
approved_by: [
|
|
||||||
{
|
|
||||||
user: {
|
|
||||||
id: 2,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
.post('/api/v4/projects/undefined/merge_requests/1/approve')
|
.post('/api/v4/projects/undefined/merge_requests/1/approve')
|
||||||
.reply(200);
|
.reply(200);
|
||||||
await expect(
|
await expect(
|
||||||
|
|
|
@ -65,7 +65,6 @@ import { getMR, updateMR } from './merge-request';
|
||||||
import { LastPipelineId } from './schema';
|
import { LastPipelineId } from './schema';
|
||||||
import type {
|
import type {
|
||||||
GitLabMergeRequest,
|
GitLabMergeRequest,
|
||||||
GitLabMergeRequestApprovals,
|
|
||||||
GitlabComment,
|
GitlabComment,
|
||||||
GitlabIssue,
|
GitlabIssue,
|
||||||
GitlabPr,
|
GitlabPr,
|
||||||
|
@ -95,7 +94,6 @@ const defaults = {
|
||||||
export const id = 'gitlab';
|
export const id = 'gitlab';
|
||||||
|
|
||||||
let draftPrefix = DRAFT_PREFIX;
|
let draftPrefix = DRAFT_PREFIX;
|
||||||
let renovateUserId: number;
|
|
||||||
|
|
||||||
export async function initPlatform({
|
export async function initPlatform({
|
||||||
endpoint,
|
endpoint,
|
||||||
|
@ -116,22 +114,19 @@ export async function initPlatform({
|
||||||
};
|
};
|
||||||
let gitlabVersion: string;
|
let gitlabVersion: string;
|
||||||
try {
|
try {
|
||||||
const user = (
|
|
||||||
await gitlabApi.getJson<{
|
|
||||||
email: string;
|
|
||||||
name: string;
|
|
||||||
id: number;
|
|
||||||
commit_email?: string;
|
|
||||||
}>(`user`, { token })
|
|
||||||
).body;
|
|
||||||
|
|
||||||
renovateUserId = user.id;
|
|
||||||
if (!gitAuthor) {
|
if (!gitAuthor) {
|
||||||
|
const user = (
|
||||||
|
await gitlabApi.getJson<{
|
||||||
|
email: string;
|
||||||
|
name: string;
|
||||||
|
id: number;
|
||||||
|
commit_email?: string;
|
||||||
|
}>(`user`, { token })
|
||||||
|
).body;
|
||||||
platformConfig.gitAuthor = `${user.name} <${
|
platformConfig.gitAuthor = `${user.name} <${
|
||||||
user.commit_email ?? user.email
|
user.commit_email ?? user.email
|
||||||
}>`;
|
}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// istanbul ignore if: experimental feature
|
// istanbul ignore if: experimental feature
|
||||||
if (process.env.RENOVATE_X_PLATFORM_VERSION) {
|
if (process.env.RENOVATE_X_PLATFORM_VERSION) {
|
||||||
gitlabVersion = process.env.RENOVATE_X_PLATFORM_VERSION;
|
gitlabVersion = process.env.RENOVATE_X_PLATFORM_VERSION;
|
||||||
|
@ -716,26 +711,6 @@ async function tryPrAutomerge(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function approvePr(pr: number): Promise<void> {
|
async function approvePr(pr: number): Promise<void> {
|
||||||
try {
|
|
||||||
const { body: approvals } =
|
|
||||||
await gitlabApi.getJson<GitLabMergeRequestApprovals>(
|
|
||||||
`projects/${config.repository}/merge_requests/${pr}/approvals`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const isApproved = approvals.approved_by?.some(
|
|
||||||
(approval) => approval.user?.id === renovateUserId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isApproved) {
|
|
||||||
logger.debug('MR is already approved');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
logger.warn(
|
|
||||||
{ err },
|
|
||||||
'GitLab: Error checking if the merge request is approved',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await gitlabApi.postJson(
|
await gitlabApi.postJson(
|
||||||
`projects/${config.repository}/merge_requests/${pr}/approve`,
|
`projects/${config.repository}/merge_requests/${pr}/approve`,
|
||||||
|
|
|
@ -77,7 +77,3 @@ export interface GitlabUserStatus {
|
||||||
emoji?: string;
|
emoji?: string;
|
||||||
availability: 'not_set' | 'busy';
|
availability: 'not_set' | 'busy';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GitLabMergeRequestApprovals {
|
|
||||||
approved_by?: { user?: GitLabUser }[];
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue