renovate/lib/workers/repository/index.ts

54 lines
1.8 KiB
TypeScript
Raw Normal View History

import fs from 'fs-extra';
import handleError from './error';
import { platform } from '../../platform';
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';
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 */ {
logger.debug({ err }, 'Error getting renovate version');
}
// istanbul ignore next
export async function renovateRepository(
repoConfig: RenovateConfig
): Promise<ProcessResult> {
2018-05-07 04:47:17 +00:00
let config = { ...repoConfig };
setMeta({ repository: config.repository });
logger.info({ renovateVersion }, 'Renovating repository');
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);
const { res, branches, branchList, packageFiles } = await processRepo(
config
);
await ensureOnboardingPr(config, packageFiles, branches);
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 */ {
const errorRes = await handleError(config, err);
repoResult = processResult(config, errorRes);
}
await platform.cleanRepo();
if (config.localDir && !config.persistRepoData) {
await fs.remove(config.localDir);
}
logger.info('Finished repository');
return repoResult;
}