/
extract-update.ts
86 lines (80 loc) · 2.42 KB
/
extract-update.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
import { RenovateConfig } from '../../../config';
import { logger } from '../../../logger';
import { PackageFile } from '../../../manager/common';
import { BranchConfig } from '../../common';
import { extractAllDependencies } from '../extract';
import { branchifyUpgrades } from '../updates/branchify';
import { raiseDeprecationWarnings } from './deprecated';
import { fetchUpdates } from './fetch';
import { sortBranches } from './sort';
import { WriteUpdateResult, writeUpdates } from './write';
export type ExtractResult = {
branches: BranchConfig[];
branchList: string[];
packageFiles: Record<string, PackageFile[]>;
};
// istanbul ignore next
function extractStats(packageFiles: Record<string, PackageFile[]>): any {
if (!packageFiles) {
return {};
}
const stats = {
managers: {},
total: {
fileCount: 0,
depCount: 0,
},
};
for (const [manager, managerPackageFiles] of Object.entries(packageFiles)) {
const fileCount = managerPackageFiles.length;
let depCount = 0;
for (const file of managerPackageFiles) {
depCount += file.deps.length;
}
stats.managers[manager] = {
fileCount,
depCount,
};
stats.total.fileCount += fileCount;
stats.total.depCount += depCount;
}
return stats;
}
export async function extract(
config: RenovateConfig
): Promise<Record<string, PackageFile[]>> {
logger.debug('extract()');
const packageFiles = await extractAllDependencies(config);
const stats = extractStats(packageFiles);
logger.info(
{ baseBranch: config.baseBranch, stats },
`Dependency extraction complete`
);
logger.trace({ config: packageFiles }, 'packageFiles');
return packageFiles;
}
export async function lookup(
config: RenovateConfig,
packageFiles: Record<string, PackageFile[]>
): Promise<ExtractResult> {
await fetchUpdates(config, packageFiles);
logger.debug({ config: packageFiles }, 'packageFiles with updates');
await raiseDeprecationWarnings(config, packageFiles);
const { branches, branchList } = await branchifyUpgrades(
config,
packageFiles
);
sortBranches(branches);
return { branches, branchList, packageFiles };
}
export async function update(
config: RenovateConfig,
branches: BranchConfig[]
): Promise<WriteUpdateResult | undefined> {
let res: WriteUpdateResult | undefined;
// istanbul ignore else
if (config.repoIsOnboarded) {
res = await writeUpdates(config, branches);
}
return res;
}