mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
feat(vsts): abandon pr after delete branch (#2086)
This commit is contained in:
parent
d68f780987
commit
56ee66381b
3 changed files with 21 additions and 16 deletions
|
@ -450,14 +450,14 @@ async function getAllRenovateBranches(branchPrefix) {
|
||||||
return branches.filter(c => c.name.startsWith(branchPrefix)).map(c => c.name);
|
return branches.filter(c => c.name.startsWith(branchPrefix)).map(c => c.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteBranch(branchName) {
|
async function deleteBranch(branchName, abandonAssociatedPr = false) {
|
||||||
logger.debug(`deleteBranch(branchName)(${branchName})`);
|
logger.debug(`deleteBranch(branchName)(${branchName})`);
|
||||||
const ref = await vstsHelper.getRefs(
|
const ref = await vstsHelper.getRefs(
|
||||||
config.repoId,
|
config.repoId,
|
||||||
vstsHelper.getNewBranchName(branchName)
|
vstsHelper.getNewBranchName(branchName)
|
||||||
);
|
);
|
||||||
const vstsApiGit = await vstsApi.gitApi();
|
const vstsApiGit = await vstsApi.gitApi();
|
||||||
return vstsApiGit.updateRefs(
|
await vstsApiGit.updateRefs(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
name: ref[0].name,
|
name: ref[0].name,
|
||||||
|
@ -467,8 +467,24 @@ async function deleteBranch(branchName) {
|
||||||
],
|
],
|
||||||
config.repoId
|
config.repoId
|
||||||
);
|
);
|
||||||
|
// istanbul ignore if
|
||||||
|
if (abandonAssociatedPr) {
|
||||||
|
const pr = await getBranchPr(branchName);
|
||||||
|
await abandonPr(pr.number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Delete PR too? or put it to abandon?
|
// istanbul ignore next
|
||||||
|
async function abandonPr(prNo) {
|
||||||
|
logger.debug(`abandonPr(prNo)(${prNo})`);
|
||||||
|
const vstsApiGit = await vstsApi.gitApi();
|
||||||
|
await vstsApiGit.updatePullRequest(
|
||||||
|
{
|
||||||
|
status: 2,
|
||||||
|
},
|
||||||
|
config.repoId,
|
||||||
|
prNo
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getBranchLastCommitTime(branchName) {
|
async function getBranchLastCommitTime(branchName) {
|
||||||
|
|
|
@ -16,16 +16,6 @@ Object {
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`platform/vsts deleteBranch should delete the branch 1`] = `
|
|
||||||
Array [
|
|
||||||
Object {
|
|
||||||
"name": "refs/head/testBranch",
|
|
||||||
"newObjectId": "0000000000000000000000000000000000000000",
|
|
||||||
"oldObjectId": "123456",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`platform/vsts ensureComment add comment 1`] = `
|
exports[`platform/vsts ensureComment add comment 1`] = `
|
||||||
Array [
|
Array [
|
||||||
Array [],
|
Array [],
|
||||||
|
|
|
@ -660,7 +660,7 @@ describe('platform/vsts', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteBranch', () => {
|
describe('deleteBranch and abandon PR', () => {
|
||||||
it('should delete the branch', async () => {
|
it('should delete the branch', async () => {
|
||||||
vstsHelper.getRefs.mockImplementation(() => [{ objectId: '123' }]);
|
vstsHelper.getRefs.mockImplementation(() => [{ objectId: '123' }]);
|
||||||
vstsApi.gitApi.mockImplementationOnce(() => ({
|
vstsApi.gitApi.mockImplementationOnce(() => ({
|
||||||
|
@ -672,8 +672,7 @@ describe('platform/vsts', () => {
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
}));
|
}));
|
||||||
const res = await vsts.deleteBranch();
|
await vsts.deleteBranch();
|
||||||
expect(res).toMatchSnapshot();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue