From f866f54a14900b394e6b371c27f4faee3485cef4 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Wed, 26 Jul 2017 10:56:11 +0200 Subject: [PATCH] fix(github): Return repoForceRebase to main config (#533) --- lib/api/github.js | 7 ++- lib/api/gitlab.js | 2 +- lib/workers/repository/apis.js | 3 +- test/api/__snapshots__/github.spec.js.snap | 66 ---------------------- test/api/__snapshots__/gitlab.spec.js.snap | 60 ++------------------ 5 files changed, 13 insertions(+), 125 deletions(-) diff --git a/lib/api/github.js b/lib/api/github.js index bceb83cf0e..f47cfb6861 100644 --- a/lib/api/github.js +++ b/lib/api/github.js @@ -141,6 +141,7 @@ async function initRepo(repoName, token, endpoint, repoLogger) { process.env.GITHUB_ENDPOINT = endpoint; } config.repoName = repoName; + const platformConfig = {}; try { const res = await ghGot(`repos/${repoName}`); config.privateRepo = res.body.private === true; @@ -160,12 +161,12 @@ async function initRepo(repoName, token, endpoint, repoLogger) { } else { logger.debug('Could not find allowed merge methods for repo'); } - config.repoForceRebase = false; + platformConfig.repoForceRebase = false; try { const branchProtection = await getBranchProtection(config.baseBranch); if (branchProtection.strict) { logger.debug('Repo has branch protection and needs PRs up-to-date'); - config.repoForceRebase = true; + platformConfig.repoForceRebase = true; } else { logger.debug( 'Repo has branch protection but does not require up-to-date' @@ -188,7 +189,7 @@ async function initRepo(repoName, token, endpoint, repoLogger) { logger.error({ err }, 'Unknown GitHub initRepo error'); throw err; } - return config; + return platformConfig; } async function getBranchProtection(branchName) { diff --git a/lib/api/gitlab.js b/lib/api/gitlab.js index 62f5d70d6b..568755a7f6 100644 --- a/lib/api/gitlab.js +++ b/lib/api/gitlab.js @@ -108,7 +108,7 @@ async function initRepo(repoName, token, endpoint, repoLogger) { logger.error({ err }, `GitLab init error`); throw err; } - return config; + return {}; } async function setBaseBranch(branchName) { diff --git a/lib/workers/repository/apis.js b/lib/workers/repository/apis.js index 484387fba0..266dad5161 100644 --- a/lib/workers/repository/apis.js +++ b/lib/workers/repository/apis.js @@ -40,13 +40,14 @@ async function initApis(inputConfig, token) { const config = Object.assign({}, inputConfig); config.api = getPlatformApi(config.platform); - await config.api.initRepo( + const platformConfig = await config.api.initRepo( config.repository, token, config.endpoint, config.logger ); // Check for presence of .npmrc in repository + Object.assign(config, platformConfig); await module.exports.setNpmrc(config); return config; } diff --git a/test/api/__snapshots__/github.spec.js.snap b/test/api/__snapshots__/github.spec.js.snap index 65e558347c..b87fdc7ff7 100644 --- a/test/api/__snapshots__/github.spec.js.snap +++ b/test/api/__snapshots__/github.spec.js.snap @@ -910,37 +910,19 @@ Array [ exports[`api/github initRepo should detect repoForceRebase 1`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": true, - "repoName": "some/repo", } `; exports[`api/github initRepo should ignore repoForceRebase 403 1`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": false, - "repoName": "some/repo", } `; exports[`api/github initRepo should ignore repoForceRebase 404 1`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": false, - "repoName": "some/repo", } `; @@ -965,14 +947,7 @@ Array [ exports[`api/github initRepo should initialise the config for the repo - 0 2`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "mergeMethod": "rebase", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": false, - "repoName": "some/repo", } `; @@ -997,14 +972,7 @@ Array [ exports[`api/github initRepo should initialise the config for the repo - 1 2`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "mergeMethod": "rebase", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": false, - "repoName": "some/repo", } `; @@ -1029,65 +997,31 @@ Array [ exports[`api/github initRepo should initialise the config for the repo - 2 2`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "mergeMethod": "rebase", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": false, - "repoName": "some/repo", } `; exports[`api/github initRepo should merge 1`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "mergeMethod": "merge", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": false, - "repoName": "some/repo", } `; exports[`api/github initRepo should not guess at merge 1`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": false, - "repoName": "some/repo", } `; exports[`api/github initRepo should rebase 1`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "mergeMethod": "rebase", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": false, - "repoName": "some/repo", } `; exports[`api/github initRepo should squash 1`] = ` Object { - "baseBranch": "master", - "baseCommitSHA": "1234", - "defaultBranch": "master", - "mergeMethod": "squash", - "owner": "theowner", - "privateRepo": false, "repoForceRebase": false, - "repoName": "some/repo", } `; diff --git a/test/api/__snapshots__/gitlab.spec.js.snap b/test/api/__snapshots__/gitlab.spec.js.snap index 94f55b3a5d..eb2b7dce45 100644 --- a/test/api/__snapshots__/gitlab.spec.js.snap +++ b/test/api/__snapshots__/gitlab.spec.js.snap @@ -233,15 +233,7 @@ Array [ ] `; -exports[`api/gitlab getFile(filePath, branchName) gets the file with v3 1`] = ` -Object { - "apiVersion": "v3", - "baseBranch": undefined, - "defaultBranch": undefined, - "email": undefined, - "repoName": "some-repo", -} -`; +exports[`api/gitlab getFile(filePath, branchName) gets the file with v3 1`] = `Object {}`; exports[`api/gitlab getFile(filePath, branchName) gets the file with v3 2`] = `"foo"`; @@ -329,15 +321,7 @@ Array [ ] `; -exports[`api/gitlab initRepo should initialise the config for the repo - 0 2`] = ` -Object { - "apiVersion": "v3", - "baseBranch": "master", - "defaultBranch": "master", - "email": "a@b.com", - "repoName": "some%2Frepo", -} -`; +exports[`api/gitlab initRepo should initialise the config for the repo - 0 2`] = `Object {}`; exports[`api/gitlab initRepo should initialise the config for the repo - 1 1`] = ` Array [ @@ -353,15 +337,7 @@ Array [ ] `; -exports[`api/gitlab initRepo should initialise the config for the repo - 1 2`] = ` -Object { - "apiVersion": "v3", - "baseBranch": "master", - "defaultBranch": "master", - "email": "a@b.com", - "repoName": "some%2Frepo", -} -`; +exports[`api/gitlab initRepo should initialise the config for the repo - 1 2`] = `Object {}`; exports[`api/gitlab initRepo should initialise the config for the repo - 2 1`] = ` Array [ @@ -377,35 +353,11 @@ Array [ ] `; -exports[`api/gitlab initRepo should initialise the config for the repo - 2 2`] = ` -Object { - "apiVersion": "v3", - "baseBranch": "master", - "defaultBranch": "master", - "email": "a@b.com", - "repoName": "some%2Frepo", -} -`; +exports[`api/gitlab initRepo should initialise the config for the repo - 2 2`] = `Object {}`; -exports[`api/gitlab initRepo should use api v4 1`] = ` -Object { - "apiVersion": "v4", - "baseBranch": "master", - "defaultBranch": "master", - "email": "a@b.com", - "repoName": "some%2Frepo", -} -`; +exports[`api/gitlab initRepo should use api v4 1`] = `Object {}`; -exports[`api/gitlab initRepo uses provided logger 1`] = ` -Object { - "apiVersion": "v3", - "baseBranch": "master", - "defaultBranch": "master", - "email": "a@b.com", - "repoName": "some%2Frepo", -} -`; +exports[`api/gitlab initRepo uses provided logger 1`] = `Object {}`; exports[`api/gitlab setBaseBranch(branchName) sets the base branch 1`] = ` Array [ -- GitLab