diff --git a/lib/platform/vsts/index.js b/lib/platform/vsts/index.js index ffeb3c595691e5dc16a72bfc941cc4b474371e64..fc4725535babc27066dbe2874f802d129189902d 100644 --- a/lib/platform/vsts/index.js +++ b/lib/platform/vsts/index.js @@ -450,14 +450,14 @@ async function getAllRenovateBranches(branchPrefix) { 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})`); const ref = await vstsHelper.getRefs( config.repoId, vstsHelper.getNewBranchName(branchName) ); const vstsApiGit = await vstsApi.gitApi(); - return vstsApiGit.updateRefs( + await vstsApiGit.updateRefs( [ { name: ref[0].name, @@ -467,8 +467,24 @@ async function deleteBranch(branchName) { ], 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) { diff --git a/test/platform/vsts/__snapshots__/index.spec.js.snap b/test/platform/vsts/__snapshots__/index.spec.js.snap index e9f1e2285a2167b6ab2a81da2d96fe7fbb879925..2dec9d4d0e8627116112ae253ec8ccbfb2481b2c 100644 --- a/test/platform/vsts/__snapshots__/index.spec.js.snap +++ b/test/platform/vsts/__snapshots__/index.spec.js.snap @@ -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`] = ` Array [ Array [], diff --git a/test/platform/vsts/index.spec.js b/test/platform/vsts/index.spec.js index 95023502c9f5e82a45bd5e36ccbf27c93bc14b78..ac84f1f12fce67aa92bf7dc29a4b47e4deda6346 100644 --- a/test/platform/vsts/index.spec.js +++ b/test/platform/vsts/index.spec.js @@ -660,7 +660,7 @@ describe('platform/vsts', () => { }); }); - describe('deleteBranch', () => { + describe('deleteBranch and abandon PR', () => { it('should delete the branch', async () => { vstsHelper.getRefs.mockImplementation(() => [{ objectId: '123' }]); vstsApi.gitApi.mockImplementationOnce(() => ({ @@ -672,8 +672,7 @@ describe('platform/vsts', () => { }, ]), })); - const res = await vsts.deleteBranch(); - expect(res).toMatchSnapshot(); + await vsts.deleteBranch(); }); });