renovate/lib/workers/repository/index.ts

67 lines
2.4 KiB
TypeScript
Raw Normal View History

import fs from 'fs-extra';
2020-05-01 16:03:48 +00:00
import { RenovateConfig } from '../../config';
import { logger, setMeta } from '../../logger';
import { deleteLocalFile } from '../../util/fs';
import { addSplit, getSplits, splitInit } from '../../util/split';
import { ensureMasterIssue } from './dependency-dashboard';
2020-05-01 16:03:48 +00:00
import handleError from './error';
import { finaliseRepo } from './finalise';
import { initRepo } from './init';
import { ensureOnboardingPr } from './onboarding/pr';
import { extractDependencies, updateRepo } from './process';
2020-05-01 16:03:48 +00:00
import { ProcessResult, processResult } from './result';
import { printRequestStats } from './stats';
let renovateVersion = 'unknown';
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
renovateVersion = require('../../../package.json').version; // eslint-disable-line global-require
2020-01-11 08:04:11 +00:00
} catch (err) /* istanbul ignore next */ {
logger.debug({ err }, 'Error getting renovate version');
}
// istanbul ignore next
export async function renovateRepository(
repoConfig: RenovateConfig
): Promise<ProcessResult> {
splitInit();
2018-05-07 04:47:17 +00:00
let config = { ...repoConfig };
setMeta({ repository: config.repository });
logger.info({ renovateVersion }, 'Repository started');
logger.trace({ config });
let repoResult: ProcessResult;
try {
await fs.ensureDir(config.localDir);
2018-09-17 12:16:01 +00:00
logger.debug('Using localDir: ' + config.localDir);
config = await initRepo(config);
addSplit('init');
const { branches, branchList, packageFiles } = await extractDependencies(
config
);
await ensureOnboardingPr(config, packageFiles, branches);
const res = await updateRepo(config, branches, branchList);
addSplit('update');
if (res !== 'automerged') {
await ensureMasterIssue(config, branches);
}
await finaliseRepo(config, branchList);
repoResult = processResult(config, res);
2018-04-04 17:35:01 +00:00
} catch (err) /* istanbul ignore next */ {
2020-01-11 08:16:22 +00:00
setMeta({ repository: config.repository });
const errorRes = await handleError(config, err);
repoResult = processResult(config, errorRes);
}
if (config.localDir && !config.persistRepoData) {
try {
await deleteLocalFile('.');
} catch (err) /* istanbul ignore if */ {
logger.warn({ err }, 'localDir deletion error');
}
}
const splits = getSplits();
logger.debug(splits, 'Repository timing splits (milliseconds)');
printRequestStats();
logger.info({ durationMs: splits.total }, 'Repository finished');
return repoResult;
}