From ef26fdb3fedefc78ae8c4dc072e1640b9fa5f178 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Sat, 17 Mar 2018 06:37:42 +0100 Subject: [PATCH] fix: mirrorMode fork patching When in mirrorMode, Renovate should keep its fork up to date --- lib/platform/github/index.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index a76a1355a9..b31bed0e29 100644 --- a/lib/platform/github/index.js +++ b/lib/platform/github/index.js @@ -70,7 +70,14 @@ async function getRepos(token, endpoint) { } // Initialize GitHub by getting base branch and SHA -async function initRepo({ repository, token, endpoint, forkMode, forkToken }) { +async function initRepo({ + repository, + token, + endpoint, + forkMode, + forkToken, + mirrorMode, +}) { logger.debug(`initRepo("${repository}")`); if (token) { logger.debug('Setting token in env for use by gh-got'); @@ -198,6 +205,32 @@ async function initRepo({ repository, token, endpoint, forkMode, forkToken }) { await delay(30000); } } + // istanbul ignore if + if (mirrorMode) { + logger.info('Renovate is in mirrorMode'); + const parentRepo = res.body.parent.full_name; + logger.debug('Parent repo is ' + parentRepo); + const parentDefaultBranch = (await get(`repos/${repository}`)).body + .default_branch; + logger.debug('Parent default branch is ' + parentDefaultBranch); + const parentSha = (await get( + `repos/${parentRepo}/git/refs/heads/${parentDefaultBranch}` + )).body.object.sha; + logger.debug('Parent sha is ' + parentSha); + // This is a lovely "hack" by GitHub that lets us force update our fork's master + // with the base commit from the parent repository + if (parentSha !== config.baseCommitSHA) { + logger.info('Updating fork default branch'); + await get.patch( + `repos/${config.repository}/git/refs/heads/${config.baseBranch}`, + { + body: { + sha: parentSha, + }, + } + ); + } + } return platformConfig; } -- GitLab