Skip to content

Commit

Permalink
fix(bitbucket): Decline PRs by separate API call (#7036)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Aug 20, 2020
1 parent d425524 commit 4459f6e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
15 changes: 13 additions & 2 deletions lib/platform/bitbucket/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1194,19 +1194,30 @@ Array [
"url": "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/5",
},
Object {
"body": "{\\"title\\":\\"title\\",\\"state\\":\\"DECLINED\\"}",
"body": "{\\"title\\":\\"title\\"}",
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "Basic YWJjOjEyMw==",
"content-length": "36",
"content-length": "17",
"content-type": "application/json",
"host": "api.bitbucket.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "PUT",
"url": "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/5",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "Basic YWJjOjEyMw==",
"host": "api.bitbucket.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "POST",
"url": "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/5/decline",
},
]
`;

Expand Down
2 changes: 2 additions & 0 deletions lib/platform/bitbucket/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,8 @@ describe('platform/bitbucket', () => {
.get('/2.0/repositories/some/repo/pullrequests/5')
.reply(200, { values: [pr] })
.put('/2.0/repositories/some/repo/pullrequests/5')
.reply(200)
.post('/2.0/repositories/some/repo/pullrequests/5/decline')
.reply(200);
await bitbucket.updatePr({
number: pr.id,
Expand Down
14 changes: 7 additions & 7 deletions lib/platform/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ export async function updatePr({
number: prNo,
prTitle: title,
prBody: description,
state: _state,
state,
}: 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 @@ -727,22 +727,22 @@ export async function updatePr({
)
).body;

const state = {
[PrState.Open]: 'OPEN',
[PrState.Closed]: 'DECLINED',
}[_state];

await bitbucketHttp.putJson(
`/2.0/repositories/${config.repository}/pullrequests/${prNo}`,
{
body: {
title,
description: sanitize(description),
reviewers: pr.reviewers,
...(state && { state }),
},
}
);

if (state === PrState.Closed && pr) {
await bitbucketHttp.postJson(
`/2.0/repositories/${config.repository}/pullrequests/${prNo}/decline`
);
}
}

export async function mergePr(
Expand Down

0 comments on commit 4459f6e

Please sign in to comment.