diff --git a/lib/config/definitions.js b/lib/config/definitions.js index 05191aeeaaa493ab53c47ae5feb41261547cc82a..7409ca3d34501fb456a126fc181675591dc35550 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -347,6 +347,7 @@ const options = [ name: 'unpublishSafe', description: 'Set a status check for unpublish-safe upgrades', type: 'boolean', + default: false, }, { name: 'prCreation', diff --git a/lib/workers/branch/index.js b/lib/workers/branch/index.js index ac181b4b1e0cfd0e62bcbb20714e42ecb3c65608..cec9425ef9479eb29abed5274d9cbcfdb4d922b1 100644 --- a/lib/workers/branch/index.js +++ b/lib/workers/branch/index.js @@ -197,15 +197,21 @@ async function ensureBranch(config) { // Return now if no branch exists return false; } - // Set unpublishable status check - if (config.unpublishSafe && typeof unpublishable !== 'undefined') { - const context = 'renovate/unpublish-safe'; - const state = unpublishable ? 'success' : 'pending'; + const context = 'renovate/unpublish-safe'; + const existingState = await api.getBranchStatusCheck(branchName, context); + // If status check was enabled and then is disabled, any "pending" status check needs to be set to "success" + const removeStatusCheck = + existingState === 'pending' && !config.unpublishSafe; + if ( + (config.unpublishSafe || removeStatusCheck) && + typeof unpublishable !== 'undefined' + ) { + // Set unpublishable status check + const state = unpublishable || removeStatusCheck ? 'success' : 'pending'; const description = unpublishable ? 'Packages are at least 24 hours old' : 'Packages < 24 hours old can be unpublished'; // Check if state needs setting - const existingState = await api.getBranchStatusCheck(branchName, context); if (existingState === state) { logger.debug('Status check is already up-to-date'); } else { diff --git a/lib/workers/package/versions.js b/lib/workers/package/versions.js index 0c4c3a59ae337344a709cf4185a9d012b9bbca3c..ff4450813a0d29e742b5ef9070cf6e1a94a5d4e5 100644 --- a/lib/workers/package/versions.js +++ b/lib/workers/package/versions.js @@ -37,6 +37,7 @@ function determineUpgrades(npmDep, config) { type: 'pin', isPin: true, automergeEnabled: true, + unpublishSafe: false, newVersion: maxSatisfying, newVersionMajor: semver.major(maxSatisfying), groupName: 'Pin Dependencies', diff --git a/test/workers/branch/index.spec.js b/test/workers/branch/index.spec.js index b97729532ea2ac4536c4563ab8fa76185b05166c..adb9b093194c002f2f9ece5fa3124d842175e7a0 100644 --- a/test/workers/branch/index.spec.js +++ b/test/workers/branch/index.spec.js @@ -168,21 +168,34 @@ describe('workers/branch', () => { branchWorker.getParentBranch.mockReturnValueOnce('dummy branch'); packageJsonHelper.setNewValue.mockReturnValueOnce('new content'); config.api.branchExists.mockReturnValueOnce(true); + config.unpublishSafe = true; config.upgrades[0].unpublishable = true; config.upgrades.push({ ...config }); config.upgrades[1].unpublishable = false; expect(await branchWorker.ensureBranch(config)).toBe(true); expect(config.api.setBranchStatus.mock.calls).toHaveLength(1); }); - it('skips branch status success', async () => { + it('skips branch status pending', async () => { branchWorker.getParentBranch.mockReturnValueOnce('dummy branch'); packageJsonHelper.setNewValue.mockReturnValueOnce('new content'); config.api.branchExists.mockReturnValueOnce(true); + config.unpublishSafe = true; + config.api.getBranchStatusCheck.mockReturnValueOnce('pending'); config.upgrades[0].unpublishable = true; - config.api.getBranchStatusCheck.mockReturnValueOnce('success'); + config.upgrades.push({ ...config }); + config.upgrades[1].unpublishable = false; expect(await branchWorker.ensureBranch(config)).toBe(true); expect(config.api.setBranchStatus.mock.calls).toHaveLength(0); }); + it('skips branch status success if setting disabled', async () => { + branchWorker.getParentBranch.mockReturnValueOnce('dummy branch'); + packageJsonHelper.setNewValue.mockReturnValueOnce('new content'); + config.api.branchExists.mockReturnValueOnce(true); + config.upgrades[0].unpublishable = true; + config.api.getBranchStatusCheck.mockReturnValueOnce('pending'); + expect(await branchWorker.ensureBranch(config)).toBe(true); + expect(config.api.setBranchStatus.mock.calls).toHaveLength(1); + }); it('automerges successful branches', async () => { branchWorker.getParentBranch.mockReturnValueOnce('dummy branch'); packageJsonHelper.setNewValue.mockReturnValueOnce('new content'); diff --git a/test/workers/package/__snapshots__/index.spec.js.snap b/test/workers/package/__snapshots__/index.spec.js.snap index a5953d969c99770019d03682440467c372a2e926..c08eb58c68aebdf708cd2290cc504fd0c4f05c4f 100644 --- a/test/workers/package/__snapshots__/index.spec.js.snap +++ b/test/workers/package/__snapshots__/index.spec.js.snap @@ -209,7 +209,7 @@ This {{#if isGitHub}}PR{{else}}MR{{/if}} has been generated by [Renovate Bot](ht "semanticPrefix": "chore(deps):", "timezone": null, "type": "error", - "unpublishSafe": true, + "unpublishSafe": false, }, ] `; diff --git a/test/workers/package/__snapshots__/versions.spec.js.snap b/test/workers/package/__snapshots__/versions.spec.js.snap index 6e47c491e009fcb5644568074654b884ba661cd3..fbf2467a0ab94f4a6998cddef77929b4a41121d4 100644 --- a/test/workers/package/__snapshots__/versions.spec.js.snap +++ b/test/workers/package/__snapshots__/versions.spec.js.snap @@ -13,6 +13,7 @@ Array [ "newVersion": "0.4.4", "newVersionMajor": 0, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, Object { @@ -76,6 +77,7 @@ Array [ "newVersion": "0.9.7", "newVersionMajor": 0, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, ] @@ -94,6 +96,7 @@ Array [ "newVersion": "1.4.1", "newVersionMajor": 1, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, ] @@ -157,6 +160,7 @@ Array [ "newVersion": "0.4.4", "newVersionMajor": 0, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, ] @@ -202,6 +206,7 @@ Array [ "newVersion": "0.4.4", "newVersionMajor": 0, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, Object { @@ -231,6 +236,7 @@ Array [ "newVersion": "0.4.4", "newVersionMajor": 0, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, Object { @@ -413,6 +419,7 @@ Array [ "newVersion": "2.0.3", "newVersionMajor": 2, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, ] @@ -469,6 +476,7 @@ Array [ "newVersion": "0.4.4", "newVersionMajor": 0, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, ] @@ -509,6 +517,7 @@ Array [ "newVersion": "0.4.4", "newVersionMajor": 0, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, ] @@ -555,6 +564,7 @@ Array [ "newVersion": "1.3.0", "newVersionMajor": 1, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, ] @@ -630,6 +640,7 @@ Array [ "newVersion": "1.0.1", "newVersionMajor": 1, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, ] @@ -751,6 +762,7 @@ Array [ "newVersion": "1.3.0", "newVersionMajor": 1, "type": "pin", + "unpublishSafe": false, "unpublishable": false, }, ]