2020-01-10 10:35:49 +00:00
|
|
|
import fs from 'fs-extra';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { RenovateConfig } from '../../config';
|
2020-01-10 10:35:49 +00:00
|
|
|
import { logger, setMeta } from '../../logger';
|
2020-07-03 19:29:04 +00:00
|
|
|
import { deleteLocalFile } from '../../util/fs';
|
2020-05-08 08:18:00 +00:00
|
|
|
import { addSplit, getSplits, splitInit } from '../../util/split';
|
2020-09-22 11:10:07 +00:00
|
|
|
import { setBranchCache } from './cache';
|
2020-07-21 13:13:56 +00:00
|
|
|
import { ensureMasterIssue } from './dependency-dashboard';
|
2020-05-01 16:03:48 +00:00
|
|
|
import handleError from './error';
|
|
|
|
import { finaliseRepo } from './finalise';
|
2020-01-10 10:35:49 +00:00
|
|
|
import { initRepo } from './init';
|
|
|
|
import { ensureOnboardingPr } from './onboarding/pr';
|
2020-05-08 06:53:39 +00:00
|
|
|
import { extractDependencies, updateRepo } from './process';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { ProcessResult, processResult } from './result';
|
2020-06-13 06:37:56 +00:00
|
|
|
import { printRequestStats } from './stats';
|
2017-06-26 12:26:49 +00:00
|
|
|
|
2020-01-11 06:50:08 +00:00
|
|
|
let renovateVersion = 'unknown';
|
|
|
|
try {
|
2020-08-10 14:18:08 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2020-01-11 06:50:08 +00:00
|
|
|
renovateVersion = require('../../../package.json').version; // eslint-disable-line global-require
|
2020-01-11 08:04:11 +00:00
|
|
|
} catch (err) /* istanbul ignore next */ {
|
2020-01-11 06:50:08 +00:00
|
|
|
logger.debug({ err }, 'Error getting renovate version');
|
|
|
|
}
|
|
|
|
|
2018-05-09 06:03:59 +00:00
|
|
|
// istanbul ignore next
|
2020-01-10 10:35:49 +00:00
|
|
|
export async function renovateRepository(
|
|
|
|
repoConfig: RenovateConfig
|
|
|
|
): Promise<ProcessResult> {
|
2020-05-08 08:18:00 +00:00
|
|
|
splitInit();
|
2018-05-07 04:47:17 +00:00
|
|
|
let config = { ...repoConfig };
|
2019-07-15 09:04:05 +00:00
|
|
|
setMeta({ repository: config.repository });
|
2020-02-24 07:43:01 +00:00
|
|
|
logger.info({ renovateVersion }, 'Repository started');
|
2018-05-09 06:03:59 +00:00
|
|
|
logger.trace({ config });
|
2020-01-10 10:35:49 +00:00
|
|
|
let repoResult: ProcessResult;
|
2017-10-18 08:29:49 +00:00
|
|
|
try {
|
2018-09-18 03:26:09 +00:00
|
|
|
await fs.ensureDir(config.localDir);
|
2018-09-17 12:16:01 +00:00
|
|
|
logger.debug('Using localDir: ' + config.localDir);
|
2017-11-05 04:45:49 +00:00
|
|
|
config = await initRepo(config);
|
2020-05-08 08:18:00 +00:00
|
|
|
addSplit('init');
|
2020-05-08 06:53:39 +00:00
|
|
|
const { branches, branchList, packageFiles } = await extractDependencies(
|
|
|
|
config
|
|
|
|
);
|
2020-04-14 10:56:44 +00:00
|
|
|
await ensureOnboardingPr(config, packageFiles, branches);
|
2020-09-01 16:33:45 +00:00
|
|
|
const res = await updateRepo(config, branches);
|
2020-05-08 08:18:00 +00:00
|
|
|
addSplit('update');
|
2020-09-22 11:10:07 +00:00
|
|
|
await setBranchCache(branches);
|
2019-07-17 08:22:13 +00:00
|
|
|
if (res !== 'automerged') {
|
|
|
|
await ensureMasterIssue(config, branches);
|
|
|
|
}
|
2018-05-07 10:59:32 +00:00
|
|
|
await finaliseRepo(config, branchList);
|
2018-10-17 10:19:02 +00:00
|
|
|
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 });
|
2018-10-17 10:19:02 +00:00
|
|
|
const errorRes = await handleError(config, err);
|
|
|
|
repoResult = processResult(config, errorRes);
|
|
|
|
}
|
|
|
|
if (config.localDir && !config.persistRepoData) {
|
2020-08-25 08:22:21 +00:00
|
|
|
try {
|
|
|
|
await deleteLocalFile('.');
|
|
|
|
} catch (err) /* istanbul ignore if */ {
|
|
|
|
logger.warn({ err }, 'localDir deletion error');
|
|
|
|
}
|
2018-04-10 07:19:24 +00:00
|
|
|
}
|
2020-05-08 08:18:00 +00:00
|
|
|
const splits = getSplits();
|
|
|
|
logger.debug(splits, 'Repository timing splits (milliseconds)');
|
2020-06-13 06:37:56 +00:00
|
|
|
printRequestStats();
|
2020-05-08 08:18:00 +00:00
|
|
|
logger.info({ durationMs: splits.total }, 'Repository finished');
|
2018-10-17 10:19:02 +00:00
|
|
|
return repoResult;
|
2017-06-26 12:26:49 +00:00
|
|
|
}
|