refactor: remove try/catch/finally from repository worker

This commit is contained in:
Rhys Arkins 2018-04-10 09:19:24 +02:00
parent 813dd1be79
commit f874ab53e7

View file

@ -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 {
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;
}