From 24b94765ff3f2dfb6ac5f73c0ffc7a0cabdd0cbf Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Sun, 31 Dec 2017 20:28:22 +0100 Subject: [PATCH] feat: skip over archived repositories (github) --- lib/platform/github/index.js | 4 ++++ lib/workers/repository/error.js | 3 +++ .../github/__snapshots__/index.spec.js.snap | 9 +++++++++ test/platform/github/index.spec.js | 15 +++++++++++++++ test/workers/repository/error.spec.js | 1 + 5 files changed, 32 insertions(+) diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index 0652b1d743..3484477939 100644 --- a/lib/platform/github/index.js +++ b/lib/platform/github/index.js @@ -89,6 +89,7 @@ async function initRepo(repoName, token, endpoint, forkMode, forkToken) { logger.trace({ repositoryDetails: res.body }, 'Repository details'); platformConfig.privateRepo = res.body.private === true; platformConfig.isFork = res.body.fork === true; + platformConfig.isArchived = res.body.archived === true; config.owner = res.body.owner.login; logger.debug(`${repoName} owner = ${config.owner}`); // Use default branch as PR target unless later overridden @@ -108,6 +109,9 @@ async function initRepo(repoName, token, endpoint, forkMode, forkToken) { logger.info({ err, res }, 'Unknown GitHub initRepo error'); throw err; } + if (platformConfig.isArchived) { + throw new Error('archived'); + } delete config.issueList; delete config.prList; delete config.fileList; diff --git a/lib/workers/repository/error.js b/lib/workers/repository/error.js index 8a6a04d2f0..a4024ebd70 100644 --- a/lib/workers/repository/error.js +++ b/lib/workers/repository/error.js @@ -12,6 +12,9 @@ async function handleError(config, err) { } else if (err.message === 'disabled') { logger.info('Repository is disabled - skipping'); return err.message; + } else if (err.message === 'archived') { + logger.info('Repository is archived - skipping'); + return err.message; } else if (err.message === 'fork') { logger.info('Repository is a fork and not manually configured - skipping'); return err.message; diff --git a/test/platform/github/__snapshots__/index.spec.js.snap b/test/platform/github/__snapshots__/index.spec.js.snap index 1be12fb0c2..86f136e553 100644 --- a/test/platform/github/__snapshots__/index.spec.js.snap +++ b/test/platform/github/__snapshots__/index.spec.js.snap @@ -547,6 +547,7 @@ Array [ exports[`platform/github initRepo should forks when forkMode 1`] = ` Object { + "isArchived": false, "isFork": false, "privateRepo": false, } @@ -571,6 +572,7 @@ Array [ exports[`platform/github initRepo should initialise the config for the repo - 0 2`] = ` Object { + "isArchived": false, "isFork": false, "privateRepo": false, } @@ -595,6 +597,7 @@ Array [ exports[`platform/github initRepo should initialise the config for the repo - 1 2`] = ` Object { + "isArchived": false, "isFork": false, "privateRepo": false, } @@ -619,6 +622,7 @@ Array [ exports[`platform/github initRepo should initialise the config for the repo - 2 2`] = ` Object { + "isArchived": false, "isFork": false, "privateRepo": false, } @@ -626,6 +630,7 @@ Object { exports[`platform/github initRepo should merge 1`] = ` Object { + "isArchived": false, "isFork": false, "privateRepo": false, } @@ -633,6 +638,7 @@ Object { exports[`platform/github initRepo should not guess at merge 1`] = ` Object { + "isArchived": false, "isFork": false, "privateRepo": false, } @@ -640,6 +646,7 @@ Object { exports[`platform/github initRepo should rebase 1`] = ` Object { + "isArchived": false, "isFork": false, "privateRepo": false, } @@ -647,6 +654,7 @@ Object { exports[`platform/github initRepo should squash 1`] = ` Object { + "isArchived": false, "isFork": false, "privateRepo": false, } @@ -654,6 +662,7 @@ Object { exports[`platform/github initRepo should update fork when forkMode 1`] = ` Object { + "isArchived": false, "isFork": false, "privateRepo": false, } diff --git a/test/platform/github/index.spec.js b/test/platform/github/index.spec.js index f9fb1a97a0..76bec2dfc5 100644 --- a/test/platform/github/index.spec.js +++ b/test/platform/github/index.spec.js @@ -324,6 +324,21 @@ describe('platform/github', () => { const config = await mergeInitRepo('some/repo', 'token'); expect(config).toMatchSnapshot(); }); + it('should throw error if archived', async () => { + get.mockReturnValueOnce({ + body: { + archived: true, + owner: {}, + }, + }); + let e; + try { + await github.initRepo('some/repo', 'token'); + } catch (err) { + e = err; + } + expect(e).toBeDefined(); + }); }); describe('getRepoForceRebase', () => { it('should detect repoForceRebase', async () => { diff --git a/test/workers/repository/error.spec.js b/test/workers/repository/error.spec.js index 7ded2443f2..916a72e69c 100644 --- a/test/workers/repository/error.spec.js +++ b/test/workers/repository/error.spec.js @@ -17,6 +17,7 @@ describe('workers/repository/error', () => { 'no-package-files', 'loops>5', 'config-validation', + 'archived', ]; errors.forEach(err => { it(`errors ${err}`, async () => { -- GitLab