2020-01-10 10:35:49 +00:00
|
|
|
import fs from 'fs-extra';
|
|
|
|
|
2019-07-15 09:04:05 +00:00
|
|
|
import handleError from './error';
|
2019-09-10 07:50:29 +00:00
|
|
|
import { platform } from '../../platform';
|
2020-01-10 10:35:49 +00:00
|
|
|
import { logger, setMeta } from '../../logger';
|
|
|
|
import { initRepo } from './init';
|
|
|
|
import { ensureOnboardingPr } from './onboarding/pr';
|
|
|
|
import { processResult, ProcessResult } from './result';
|
|
|
|
import { processRepo } from './process';
|
|
|
|
import { finaliseRepo } from './finalise';
|
|
|
|
import { ensureMasterIssue } from './master-issue';
|
|
|
|
import { RenovateConfig } from '../../config';
|
2017-06-26 12:26:49 +00:00
|
|
|
|
2020-01-11 06:50:08 +00:00
|
|
|
let renovateVersion = 'unknown';
|
|
|
|
try {
|
|
|
|
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> {
|
2018-05-07 04:47:17 +00:00
|
|
|
let config = { ...repoConfig };
|
2019-07-15 09:04:05 +00:00
|
|
|
setMeta({ repository: config.repository });
|
2020-01-11 06:50:08 +00:00
|
|
|
logger.info({ renovateVersion }, 'Renovating repository');
|
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);
|
2018-05-09 06:03:59 +00:00
|
|
|
const { res, branches, branchList, packageFiles } = await processRepo(
|
|
|
|
config
|
|
|
|
);
|
|
|
|
await ensureOnboardingPr(config, packageFiles, 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 */ {
|
2018-10-17 10:19:02 +00:00
|
|
|
const errorRes = await handleError(config, err);
|
|
|
|
repoResult = processResult(config, errorRes);
|
|
|
|
}
|
|
|
|
await platform.cleanRepo();
|
|
|
|
if (config.localDir && !config.persistRepoData) {
|
|
|
|
await fs.remove(config.localDir);
|
2018-04-10 07:19:24 +00:00
|
|
|
}
|
2018-10-17 10:19:02 +00:00
|
|
|
logger.info('Finished repository');
|
|
|
|
return repoResult;
|
2017-06-26 12:26:49 +00:00
|
|
|
}
|