mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
refactor(azure): Support state changes for updatePr (#7014)
This commit is contained in:
parent
cc8652e38c
commit
6547d37ae0
3 changed files with 43 additions and 1 deletions
|
@ -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 [
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue