From f874ab53e739f9b5ad23a7e855146d55df922134 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Tue, 10 Apr 2018 09:19:24 +0200 Subject: [PATCH] refactor: remove try/catch/finally from repository worker --- lib/workers/repository/index.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/workers/repository/index.js b/lib/workers/repository/index.js index b25600d6d8..07303cbdca 100644 --- a/lib/workers/repository/index.js +++ b/lib/workers/repository/index.js @@ -20,6 +20,7 @@ async function renovateRepository(repoConfig) { logger.info('Renovating repository'); logger.trace({ config }, 'renovateRepository()'); let commonConfig; + let res; try { config = await initApis(config); config = await initRepo(config); @@ -40,11 +41,11 @@ async function renovateRepository(repoConfig) { configs[index] = config; } // Combine all the results into one - for (const [index, res] of configs.entries()) { + for (const [index, entry] of configs.entries()) { if (index === 0) { - config = res; + config = entry; } else { - config.branches = config.branches.concat(res.branches); + config.branches = config.branches.concat(entry.branches); } } // istanbul ignore next @@ -72,21 +73,25 @@ async function renovateRepository(repoConfig) { // Sort by prTitle return a.prTitle < b.prTitle ? -1 : 1; }); - const res = config.repoIsOnboarded + res = config.repoIsOnboarded ? await writeUpdates(config) : await ensureOnboardingPr(config); await validatePrs(commonConfig || config); - return res; } catch (err) /* istanbul ignore next */ { - const res = await handleError(config, err); - return res; - } finally { - logger.setMeta({ repository: config.repository }); - config.branchPrefix = commonConfig - ? commonConfig.branchPrefix - : config.branchPrefix; + res = await handleError(config, err); + } + logger.setMeta({ repository: config.repository }); + config.branchPrefix = commonConfig + ? commonConfig.branchPrefix + : config.branchPrefix; + try { await pruneStaleBranches(config); platform.cleanRepo(); - logger.info('Finished repository'); + } catch (err) /* istanbul ignore next */ { + logger.error( + { err, message: err.message }, + 'Error pruning/cleaning repository' + ); } + return res; }