refactor(azure): Support state changes for updatePr (#7014)

This commit is contained in:
Sergio Zharinov 2020-08-18 16:28:18 +04:00 committed by GitHub
parent cc8652e38c
commit 6547d37ae0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 1 deletions

View file

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

View file

@ -613,6 +613,24 @@ describe('platform/azure', () => {
});
expect(updatePullRequest.mock.calls).toMatchSnapshot();
});
it('should close 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.Closed,
});
expect(updatePullRequest.mock.calls).toMatchSnapshot();
});
});
describe('ensureComment', () => {

View file

@ -3,8 +3,8 @@ import {
GitPullRequest,
GitPullRequestCommentThread,
GitPullRequestMergeStrategy,
PullRequestStatus,
} from 'azure-devops-node-api/interfaces/GitInterfaces';
import { RenovateConfig } from '../../config/common';
import { REPOSITORY_DISABLED } from '../../constants/error-messages';
import { PLATFORM_TYPE_AZURE } from '../../constants/platforms';
import { logger } from '../../logger';
@ -390,15 +390,25 @@ export async function updatePr({
number: prNo,
prTitle: title,
prBody: body,
state,
}: 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));
}
await azureApiGit.updatePullRequest(objToUpdate, config.repoId, prNo);
}