diff --git a/lib/workers/branch/status-checks.js b/lib/workers/branch/status-checks.js index 0488a3aa59261de6082aeb50247c860e6a6baec4..97425c43b36a8b046ec74912c2ddb9695a999ca8 100644 --- a/lib/workers/branch/status-checks.js +++ b/lib/workers/branch/status-checks.js @@ -3,6 +3,9 @@ module.exports = { }; async function setUnpublishable(config) { + if (!config.unpublishSafe) { + return; + } let unpublishable; for (const upgrade of config.upgrades) { if (typeof upgrade.unpublishable !== 'undefined') { @@ -21,15 +24,9 @@ async function setUnpublishable(config) { config.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' - ) { + if (config.unpublishSafe && typeof unpublishable !== 'undefined') { // Set unpublishable status check - const state = unpublishable || removeStatusCheck ? 'success' : 'pending'; + const state = unpublishable ? 'success' : 'pending'; const description = unpublishable ? 'Packages are at least 24 hours old' : 'Packages < 24 hours old can be unpublished'; diff --git a/test/workers/branch/status-checks.spec.js b/test/workers/branch/status-checks.spec.js index d24facf7b5748c5c4e027ff89ed312c59f3e5c22..2cc53eda086119829d6922cc5799917e9e1e2543 100644 --- a/test/workers/branch/status-checks.spec.js +++ b/test/workers/branch/status-checks.spec.js @@ -15,20 +15,12 @@ describe('workers/branch/status-checks', () => { afterEach(() => { jest.resetAllMocks(); }); - it('defaults to unpublishable', async () => { - await setUnpublishable(config); - expect(platform.getBranchStatusCheck.mock.calls.length).toBe(1); - expect(platform.setBranchStatus.mock.calls.length).toBe(0); - }); - it('finds unpublishable true', async () => { - config.upgrades = [{ unpublishable: true }]; + it('returns if not configured', async () => { await setUnpublishable(config); - expect(platform.getBranchStatusCheck.mock.calls.length).toBe(1); - expect(platform.setBranchStatus.mock.calls.length).toBe(0); + expect(platform.getBranchStatusCheck.mock.calls.length).toBe(0); }); - it('removes status check', async () => { - config.upgrades = [{ unpublishable: true }]; - platform.getBranchStatusCheck.mockReturnValueOnce('pending'); + it('defaults to unpublishable', async () => { + config.unpublishSafe = true; await setUnpublishable(config); expect(platform.getBranchStatusCheck.mock.calls.length).toBe(1); expect(platform.setBranchStatus.mock.calls.length).toBe(1);