diff --git a/lib/workers/pr/index.js b/lib/workers/pr/index.js index 00bd6a2008feff7aac9cb1efe60f83e29b8115f3..73d72079d8f4c3e982a2355bd47b3ef5c7fbec19 100644 --- a/lib/workers/pr/index.js +++ b/lib/workers/pr/index.js @@ -19,16 +19,23 @@ async function ensurePr(prConfig) { logger.debug('Found existing PR'); } config.upgrades = []; - const branchStatus = await platform.getBranchStatus( - branchName, - config.requiredStatusChecks - ); if (config.lockFileErrors && config.lockFileErrors.length) { logger.debug('Forcing PR because of lock file errors'); config.forcePr = true; } + let branchStatus; + async function getBranchStatus() { + if (!branchStatus) { + branchStatus = await platform.getBranchStatus( + branchName, + config.requiredStatusChecks + ); + } + return branchStatus; + } + // Only create a PR if a branch automerge has failed if ( config.automerge === true && @@ -36,9 +43,12 @@ async function ensurePr(prConfig) { !config.forcePr ) { logger.debug( - `Branch is configured for branch automerge, branchStatus is: ${branchStatus}` + `Branch is configured for branch automerge, branch status) is: ${await getBranchStatus()}` ); - if (branchStatus === 'pending' || branchStatus === 'running') { + if ( + (await getBranchStatus()) === 'pending' || + (await getBranchStatus()) === 'running' + ) { logger.debug('Checking how long this branch has been pending'); const lastCommitTime = await platform.getBranchLastCommitTime(branchName); const currentTime = new Date(); @@ -51,7 +61,7 @@ async function ensurePr(prConfig) { config.forcePr = true; } } - if (config.forcePr || branchStatus === 'failure') { + if (config.forcePr || (await getBranchStatus()) === 'failure') { logger.debug(`Branch tests failed, so will create PR`); } else { return null; @@ -59,8 +69,10 @@ async function ensurePr(prConfig) { } if (config.prCreation === 'status-success') { logger.debug('Checking branch combined status'); - if (branchStatus !== 'success') { - logger.debug(`Branch status is "${branchStatus}" - not creating PR`); + if ((await getBranchStatus()) !== 'success') { + logger.debug( + `Branch status is "${await getBranchStatus()}" - not creating PR` + ); return null; } logger.debug('Branch status success'); @@ -70,8 +82,13 @@ async function ensurePr(prConfig) { !config.forcePr ) { logger.debug('Checking branch combined status'); - if (branchStatus === 'pending' || branchStatus === 'running') { - logger.debug(`Branch status is "${branchStatus}" - checking timeout`); + if ( + (await getBranchStatus()) === 'pending' || + (await getBranchStatus()) === 'running' + ) { + logger.debug( + `Branch status is "${await getBranchStatus()}" - checking timeout` + ); const lastCommitTime = await platform.getBranchLastCommitTime(branchName); const currentTime = new Date(); const millisecondsPerHour = 1000 * 60 * 60; @@ -205,7 +222,7 @@ async function ensurePr(prConfig) { try { if (existingPr) { logger.debug('Processing existing PR'); - if (config.automerge && branchStatus === 'failure') { + if (config.automerge && (await getBranchStatus()) === 'failure') { logger.debug(`Setting assignees and reviewers as status checks failed`); await addAssigneesReviewers(config, existingPr); } @@ -291,7 +308,7 @@ async function ensurePr(prConfig) { platform.ensureComment(pr.number, subject, content); } // Skip assign and review if automerging PR - if (config.automerge && branchStatus !== 'failure') { + if (config.automerge && (await getBranchStatus()) !== 'failure') { logger.debug( `Skipping assignees and reviewers as automerge=${config.automerge}` );