-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathindex.ts
90 lines (89 loc) · 3.33 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import fs from 'fs-extra';
import { GlobalConfig } from '../../config/global';
import { applySecretsToConfig } from '../../config/secrets';
import type { RenovateConfig } from '../../config/types';
import { pkg } from '../../expose.cjs';
import { logger, setMeta } from '../../logger';
import { removeDanglingContainers } from '../../util/exec/docker';
import { deleteLocalFile, privateCacheDir } from '../../util/fs';
import * as queue from '../../util/http/queue';
import { addSplit, getSplits, splitInit } from '../../util/split';
import { setBranchCache } from './cache';
import { ensureDependencyDashboard } from './dependency-dashboard';
import handleError from './error';
import { finaliseRepo } from './finalise';
import { initRepo } from './init';
import { ensureOnboardingPr } from './onboarding/pr';
import { extractDependencies, updateRepo } from './process';
import { ProcessResult, processResult } from './result';
import { printRequestStats } from './stats';
// istanbul ignore next
export async function renovateRepository(
repoConfig: RenovateConfig,
canRetry = true
): Promise<ProcessResult | undefined> {
splitInit();
let config = GlobalConfig.set(
applySecretsToConfig(repoConfig, undefined, false)
);
await removeDanglingContainers();
setMeta({ repository: config.repository });
logger.info({ renovateVersion: pkg.version }, 'Repository started');
logger.trace({ config });
let repoResult: ProcessResult | undefined;
queue.clear();
const localDir = GlobalConfig.get('localDir')!;
try {
await fs.ensureDir(localDir);
logger.debug('Using localDir: ' + localDir);
config = await initRepo(config);
addSplit('init');
const { branches, branchList, packageFiles } = await extractDependencies(
config
);
if (
GlobalConfig.get('dryRun') !== 'lookup' &&
GlobalConfig.get('dryRun') !== 'extract'
) {
await ensureOnboardingPr(config, packageFiles, branches);
const res = await updateRepo(config, branches);
setMeta({ repository: config.repository });
addSplit('update');
await setBranchCache(branches);
if (res === 'automerged') {
if (canRetry) {
logger.info('Renovating repository again after automerge result');
const recursiveRes = await renovateRepository(repoConfig, false);
return recursiveRes;
}
logger.debug(`Automerged but already retried once`);
} else {
await ensureDependencyDashboard(config, branches);
}
await finaliseRepo(config, branchList);
// TODO #7154
repoResult = processResult(config, res!);
}
} catch (err) /* istanbul ignore next */ {
setMeta({ repository: config.repository });
const errorRes = await handleError(config, err);
repoResult = processResult(config, errorRes);
}
if (localDir && !repoConfig.persistRepoData) {
try {
await deleteLocalFile('.');
} catch (err) /* istanbul ignore if */ {
logger.warn({ err }, 'localDir deletion error');
}
}
try {
await fs.remove(privateCacheDir());
} catch (err) /* istanbul ignore if */ {
logger.warn({ err }, 'privateCacheDir deletion error');
}
const splits = getSplits();
logger.debug(splits, 'Repository timing splits (milliseconds)');
printRequestStats();
logger.info({ durationMs: splits.total }, 'Repository finished');
return repoResult;
}