diff --git a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap index dfd3a2f8d645c2..76786c3e693e82 100644 --- a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap @@ -1344,12 +1344,23 @@ Array [ "url": "https://api.bitbucket.org/2.0/repositories/some/repo", }, Object { - "body": "{\\"title\\":\\"title\\",\\"description\\":\\"body\\"}", "headers": Object { "accept": "application/json", "accept-encoding": "gzip, deflate", "authorization": "Basic YWJjOjEyMw==", - "content-length": 38, + "host": "api.bitbucket.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/5", + }, + Object { + "body": "{\\"title\\":\\"title\\",\\"description\\":\\"body\\",\\"reviewers\\":[{\\"display_name\\":\\"Jane Smith\\",\\"uuid\\":\\"{90b6646d-1724-4a64-9fd9-539515fe94e9}\\"}]}", + "headers": Object { + "accept": "application/json", + "accept-encoding": "gzip, deflate", + "authorization": "Basic YWJjOjEyMw==", + "content-length": 130, "content-type": "application/json", "host": "api.bitbucket.org", "user-agent": "https://github.com/renovatebot/renovate", @@ -1359,3 +1370,32 @@ Array [ }, ] `; + +exports[`platform/bitbucket updatePr() throws an error on failure to get current list of reviewers 1`] = `"Response code 500 (Internal Server Error)"`; + +exports[`platform/bitbucket updatePr() throws an error on failure to get current list of reviewers 2`] = ` +Array [ + 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": "GET", + "url": "https://api.bitbucket.org/2.0/repositories/some/repo", + }, + 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": "GET", + "url": "https://api.bitbucket.org/2.0/repositories/some/repo/pullrequests/5", + }, +] +`; diff --git a/lib/platform/bitbucket/index.spec.ts b/lib/platform/bitbucket/index.spec.ts index e748bea7dee5de..9ae1831a45ba25 100644 --- a/lib/platform/bitbucket/index.spec.ts +++ b/lib/platform/bitbucket/index.spec.ts @@ -773,11 +773,29 @@ describe('platform/bitbucket', () => { describe('updatePr()', () => { it('puts PR', async () => { + const reviewer = { + display_name: 'Jane Smith', + uuid: '{90b6646d-1724-4a64-9fd9-539515fe94e9}', + }; const scope = await initRepoMock(); - scope.put('/2.0/repositories/some/repo/pullrequests/5').reply(200); + scope + .get('/2.0/repositories/some/repo/pullrequests/5') + .reply(200, { reviewers: [reviewer] }) + .put('/2.0/repositories/some/repo/pullrequests/5') + .reply(200); await bitbucket.updatePr(5, 'title', 'body'); expect(httpMock.getTrace()).toMatchSnapshot(); }); + it('throws an error on failure to get current list of reviewers', async () => { + const scope = await initRepoMock(); + scope + .get('/2.0/repositories/some/repo/pullrequests/5') + .reply(500, undefined); + await expect(() => + bitbucket.updatePr(5, 'title', 'body') + ).rejects.toThrowErrorMatchingSnapshot(); + expect(httpMock.getTrace()).toMatchSnapshot(); + }); }); describe('mergePr()', () => { diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index f3e217b521f542..19089d509d2d12 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -281,6 +281,7 @@ interface PrResponse { name: string; }; }; + reviewers: Array; } // Gets details for a PR @@ -785,10 +786,21 @@ export async function updatePr( description: string ): Promise { logger.debug(`updatePr(${prNo}, ${title}, body)`); + // Updating a PR in Bitbucket will clear the reviewers if reviewers is not present + const pr = ( + await bitbucketHttp.getJson( + `/2.0/repositories/${config.repository}/pullrequests/${prNo}` + ) + ).body; + await bitbucketHttp.putJson( `/2.0/repositories/${config.repository}/pullrequests/${prNo}`, { - body: { title, description: sanitize(description) }, + body: { + title, + description: sanitize(description), + reviewers: pr.reviewers, + }, } ); }