Skip to content

Commit

Permalink
Revert "Revert "Merge branch 'main' into feat/update-baseBranch""
Browse files Browse the repository at this point in the history
This reverts commit 08ce058.
  • Loading branch information
RahulGautamSingh committed May 20, 2023
1 parent 08ce058 commit 20c99e1
Show file tree
Hide file tree
Showing 24 changed files with 179 additions and 24 deletions.
5 changes: 5 additions & 0 deletions lib/modules/platform/azure/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ exports[`modules/platform/azure/index updatePr(prNo, title, body, platformOption
{
"description": "Hello world again",
"status": 2,
"targetRefName": "refs/heads/target_branch",
"title": "The New Title",
},
"1",
Expand All @@ -295,13 +296,15 @@ exports[`modules/platform/azure/index updatePr(prNo, title, body, platformOption
[
{
"status": 1,
"targetRefName": "refs/heads/target_branch",
},
"1",
1234,
],
[
{
"description": "Hello world again",
"targetRefName": "refs/heads/target_branch",
"title": "The New Title",
},
"1",
Expand All @@ -315,6 +318,7 @@ exports[`modules/platform/azure/index updatePr(prNo, title, body, platformOption
[
{
"description": "Hello world again",
"targetRefName": "refs/heads/target_branch",
"title": "The New Title",
},
"1",
Expand All @@ -327,6 +331,7 @@ exports[`modules/platform/azure/index updatePr(prNo, title, body, platformOption
[
[
{
"targetRefName": "refs/heads/target_branch",
"title": "The New Title - autoclose",
},
"1",
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/platform/azure/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ describe('modules/platform/azure/index', () => {
number: 1234,
prTitle: 'The New Title',
prBody: 'Hello world again',
targetBranch: 'target_branch',
});
expect(updatePullRequest.mock.calls).toMatchSnapshot();
});
Expand All @@ -842,6 +843,7 @@ describe('modules/platform/azure/index', () => {
await azure.updatePr({
number: 1234,
prTitle: 'The New Title - autoclose',
targetBranch: 'target_branch',
});
expect(updatePullRequest.mock.calls).toMatchSnapshot();
});
Expand All @@ -860,6 +862,7 @@ describe('modules/platform/azure/index', () => {
prTitle: 'The New Title',
prBody: 'Hello world again',
state: 'closed',
targetBranch: 'target_branch',
});
expect(updatePullRequest.mock.calls).toMatchSnapshot();
});
Expand All @@ -878,6 +881,7 @@ describe('modules/platform/azure/index', () => {
prTitle: 'The New Title',
prBody: 'Hello world again',
state: 'open',
targetBranch: 'target_branch',
});
expect(updatePullRequest.mock.calls).toMatchSnapshot();
});
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/platform/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,16 @@ export async function updatePr({
prTitle: title,
prBody: body,
state,
targetBranch,
platformOptions,
}: UpdatePrConfig): Promise<void> {
logger.debug(`updatePr(${prNo}, ${title}, body)`);

const azureApiGit = await azureApi.gitApi();
const targetRefName = getNewBranchName(targetBranch);
const objToUpdate: GitPullRequest = {
title,
targetRefName,
};

if (body) {
Expand All @@ -523,7 +526,7 @@ export async function updatePr({

if (state === 'open') {
await azureApiGit.updatePullRequest(
{ status: PullRequestStatus.Active },
{ status: PullRequestStatus.Active, targetRefName },
config.repoId,
prNo
);
Expand Down
33 changes: 29 additions & 4 deletions lib/modules/platform/bitbucket-server/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,7 @@ describe('modules/platform/bitbucket-server/index', () => {
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).toResolve();
});
Expand All @@ -1443,6 +1444,7 @@ describe('modules/platform/bitbucket-server/index', () => {
prTitle: 'title',
prBody: 'body',
state: 'closed',
targetBranch: 'target_branch',
})
).toResolve();
});
Expand All @@ -1469,6 +1471,7 @@ describe('modules/platform/bitbucket-server/index', () => {
prTitle: 'title',
prBody: 'body',
state: 'open',
targetBranch: 'target_branch',
})
).toResolve();
});
Expand All @@ -1480,6 +1483,7 @@ describe('modules/platform/bitbucket-server/index', () => {
number: null as any,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).rejects.toThrow(REPOSITORY_NOT_FOUND);
});
Expand All @@ -1492,7 +1496,12 @@ describe('modules/platform/bitbucket-server/index', () => {
)
.reply(404);
await expect(
bitbucket.updatePr({ number: 4, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 4,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).rejects.toThrow(REPOSITORY_NOT_FOUND);
});

Expand All @@ -1509,7 +1518,12 @@ describe('modules/platform/bitbucket-server/index', () => {
.reply(404);

await expect(
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).rejects.toThrow(REPOSITORY_NOT_FOUND);
});

Expand Down Expand Up @@ -1558,6 +1572,7 @@ describe('modules/platform/bitbucket-server/index', () => {
prTitle: 'title',
prBody: 'body',
state: 'open',
targetBranch: 'target_branch',
})
).toResolve();
});
Expand All @@ -1575,7 +1590,12 @@ describe('modules/platform/bitbucket-server/index', () => {
.reply(409);

await expect(
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).rejects.toThrow(REPOSITORY_CHANGED);
});

Expand All @@ -1592,7 +1612,12 @@ describe('modules/platform/bitbucket-server/index', () => {
.reply(405);

await expect(
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).rejects.toThrowErrorMatchingSnapshot();
});
});
Expand Down
5 changes: 5 additions & 0 deletions lib/modules/platform/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ export async function updatePr({
prBody: rawDescription,
state,
bitbucketInvalidReviewers,
targetBranch,
}: UpdatePrConfig & {
bitbucketInvalidReviewers: string[] | undefined;
}): Promise<void> {
Expand Down Expand Up @@ -878,6 +879,9 @@ export async function updatePr({
(name: string) => !bitbucketInvalidReviewers?.includes(name)
)
.map((name: string) => ({ user: { name } })),
toRef: {
id: `refs/heads/${targetBranch}`,
},
},
}
);
Expand Down Expand Up @@ -919,6 +923,7 @@ export async function updatePr({
prBody: rawDescription,
state,
bitbucketInvalidReviewers: invalidReviewers,
targetBranch,
});
} else {
throw new Error(REPOSITORY_CHANGED);
Expand Down
50 changes: 43 additions & 7 deletions lib/modules/platform/bitbucket/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,12 @@ describe('modules/platform/bitbucket/index', () => {
.put('/2.0/repositories/some/repo/pullrequests/5')
.reply(200);
await expect(
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).toResolve();
});

Expand Down Expand Up @@ -1238,7 +1243,12 @@ describe('modules/platform/bitbucket/index', () => {
.put('/2.0/repositories/some/repo/pullrequests/5')
.reply(200);
await expect(
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).toResolve();
});

Expand Down Expand Up @@ -1282,7 +1292,12 @@ describe('modules/platform/bitbucket/index', () => {
.reply(200);

await expect(
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).toResolve();
});

Expand Down Expand Up @@ -1314,7 +1329,12 @@ describe('modules/platform/bitbucket/index', () => {
)
.reply(401);
await expect(() =>
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).rejects.toThrow(new Error('Response code 401 (Unauthorized)'));
});

Expand All @@ -1339,7 +1359,12 @@ describe('modules/platform/bitbucket/index', () => {
},
});
await expect(() =>
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).rejects.toThrowErrorMatchingSnapshot();
});

Expand All @@ -1364,7 +1389,12 @@ describe('modules/platform/bitbucket/index', () => {
},
});
await expect(() =>
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).rejects.toThrow(new Error('Response code 400 (Bad Request)'));
});

Expand All @@ -1374,7 +1404,12 @@ describe('modules/platform/bitbucket/index', () => {
.get('/2.0/repositories/some/repo/pullrequests/5')
.reply(500, undefined);
await expect(() =>
bitbucket.updatePr({ number: 5, prTitle: 'title', prBody: 'body' })
bitbucket.updatePr({
number: 5,
prTitle: 'title',
prBody: 'body',
targetBranch: 'target_branch',
})
).rejects.toThrowErrorMatchingSnapshot();
});

Expand All @@ -1393,6 +1428,7 @@ describe('modules/platform/bitbucket/index', () => {
number: pr.id,
prTitle: pr.title,
state: 'closed',
targetBranch: 'target_branch',
})
).toBeUndefined();
});
Expand Down
11 changes: 11 additions & 0 deletions lib/modules/platform/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ export async function updatePr({
prTitle: title,
prBody: description,
state,
targetBranch,
}: UpdatePrConfig): Promise<void> {
logger.debug(`updatePr(${prNo}, ${title}, body)`);
// Updating a PR in Bitbucket will clear the reviewers if reviewers is not present
Expand All @@ -896,6 +897,11 @@ export async function updatePr({
title,
description: sanitize(description),
reviewers: pr.reviewers,
destination: {
branch: {
name: targetBranch,
},
},
},
}
);
Expand All @@ -913,6 +919,11 @@ export async function updatePr({
title,
description: sanitize(description),
reviewers: sanitizedReviewers,
destination: {
branch: {
name: targetBranch,
},
},
},
}
);
Expand Down
5 changes: 5 additions & 0 deletions lib/modules/platform/codecommit/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ describe('modules/platform/codecommit/index', () => {
prTitle: 'title',
prBody: 'body',
state: 'open',
targetBranch: 'target_branch',
})
).toResolve();
});
Expand Down Expand Up @@ -725,6 +726,7 @@ describe('modules/platform/codecommit/index', () => {
prTitle: 'title',
prBody: 'new description',
state: 'open',
targetBranch: 'target_branch',
})
).toResolve();
});
Expand All @@ -751,6 +753,7 @@ describe('modules/platform/codecommit/index', () => {
prTitle: 'title',
prBody: 'new description',
state: 'open',
targetBranch: 'target_branch',
})
).toResolve();
});
Expand All @@ -767,6 +770,7 @@ describe('modules/platform/codecommit/index', () => {
prTitle: 'title',
prBody: 'body',
state: 'open',
targetBranch: 'target_branch',
})
).toResolve();
});
Expand All @@ -781,6 +785,7 @@ describe('modules/platform/codecommit/index', () => {
prTitle: 'title',
prBody: 'body',
state: 'closed',
targetBranch: 'target_branch',
})
).toResolve();
});
Expand Down
Loading

0 comments on commit 20c99e1

Please sign in to comment.