fix(azure): Separate API call for the reopening PR state (#7050)

Co-authored-by: Jamie Magee <JamieMagee@users.noreply.github.com>
This commit is contained in:
Sergio Zharinov 2020-08-24 12:41:07 +04:00 committed by GitHub
parent d22ae1e4bd
commit 786ff757b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 6 deletions

View file

@ -188,6 +188,26 @@ Array [
]
`;
exports[`platform/azure updatePr(prNo, title, body) should reopen the PR 1`] = `
Array [
Array [
Object {
"status": 1,
},
"1",
1234,
],
Array [
Object {
"description": undefined,
"title": "The New Title",
},
"1",
1234,
],
]
`;
exports[`platform/azure updatePr(prNo, title, body) should update the PR 1`] = `
Array [
Array [

View file

@ -631,6 +631,24 @@ describe('platform/azure', () => {
});
expect(updatePullRequest.mock.calls).toMatchSnapshot();
});
it('should reopen the PR', async () => {
await initRepo({ repository: 'some/repo' });
const updatePullRequest = jest.fn();
azureApi.gitApi.mockImplementationOnce(
() =>
({
updatePullRequest,
} as any)
);
await azure.updatePr({
number: 1234,
prTitle: 'The New Title',
prBody: 'Hello world again',
state: PrState.Open,
});
expect(updatePullRequest.mock.calls).toMatchSnapshot();
});
});
describe('ensureComment', () => {

View file

@ -373,21 +373,25 @@ export async function updatePr({
}: UpdatePrConfig): Promise<void> {
logger.debug(`updatePr(${prNo}, ${title}, body)`);
const status = {
[PrState.Open]: PullRequestStatus.Active,
[PrState.Closed]: PullRequestStatus.Abandoned,
}[state];
const azureApiGit = await azureApi.gitApi();
const objToUpdate: GitPullRequest = {
title,
...(status && { status }),
};
if (body) {
objToUpdate.description = azureHelper.max4000Chars(sanitize(body));
}
if (state === PrState.Open) {
await azureApiGit.updatePullRequest(
{ status: PullRequestStatus.Active },
config.repoId,
prNo
);
} else if (state === PrState.Closed) {
objToUpdate.status = PullRequestStatus.Abandoned;
}
await azureApiGit.updatePullRequest(objToUpdate, config.repoId, prNo);
}