mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26: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`] = `
|
exports[`platform/azure updatePr(prNo, title, body) should update the PR 1`] = `
|
||||||
Array [
|
Array [
|
||||||
Array [
|
Array [
|
||||||
|
|
|
@ -613,6 +613,24 @@ describe('platform/azure', () => {
|
||||||
});
|
});
|
||||||
expect(updatePullRequest.mock.calls).toMatchSnapshot();
|
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', () => {
|
describe('ensureComment', () => {
|
||||||
|
|
|
@ -3,8 +3,8 @@ import {
|
||||||
GitPullRequest,
|
GitPullRequest,
|
||||||
GitPullRequestCommentThread,
|
GitPullRequestCommentThread,
|
||||||
GitPullRequestMergeStrategy,
|
GitPullRequestMergeStrategy,
|
||||||
|
PullRequestStatus,
|
||||||
} from 'azure-devops-node-api/interfaces/GitInterfaces';
|
} from 'azure-devops-node-api/interfaces/GitInterfaces';
|
||||||
import { RenovateConfig } from '../../config/common';
|
|
||||||
import { REPOSITORY_DISABLED } from '../../constants/error-messages';
|
import { REPOSITORY_DISABLED } from '../../constants/error-messages';
|
||||||
import { PLATFORM_TYPE_AZURE } from '../../constants/platforms';
|
import { PLATFORM_TYPE_AZURE } from '../../constants/platforms';
|
||||||
import { logger } from '../../logger';
|
import { logger } from '../../logger';
|
||||||
|
@ -390,15 +390,25 @@ export async function updatePr({
|
||||||
number: prNo,
|
number: prNo,
|
||||||
prTitle: title,
|
prTitle: title,
|
||||||
prBody: body,
|
prBody: body,
|
||||||
|
state,
|
||||||
}: UpdatePrConfig): Promise<void> {
|
}: UpdatePrConfig): Promise<void> {
|
||||||
logger.debug(`updatePr(${prNo}, ${title}, body)`);
|
logger.debug(`updatePr(${prNo}, ${title}, body)`);
|
||||||
|
|
||||||
|
const status = {
|
||||||
|
[PrState.Open]: PullRequestStatus.Active,
|
||||||
|
[PrState.Closed]: PullRequestStatus.Abandoned,
|
||||||
|
}[state];
|
||||||
|
|
||||||
const azureApiGit = await azureApi.gitApi();
|
const azureApiGit = await azureApi.gitApi();
|
||||||
const objToUpdate: GitPullRequest = {
|
const objToUpdate: GitPullRequest = {
|
||||||
title,
|
title,
|
||||||
|
...(status && { status }),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (body) {
|
if (body) {
|
||||||
objToUpdate.description = azureHelper.max4000Chars(sanitize(body));
|
objToUpdate.description = azureHelper.max4000Chars(sanitize(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
await azureApiGit.updatePullRequest(objToUpdate, config.repoId, prNo);
|
await azureApiGit.updatePullRequest(objToUpdate, config.repoId, prNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue