diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index a76a1355a91e5ac284cd1b819d875d287aa0ed3d..b31bed0e294f9011c5b6adf9641bc3ab26421b37 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; }