/
fetch.ts
119 lines (115 loc) · 3.89 KB
/
fetch.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import pAll from 'p-all';
import {
ManagerConfig,
RenovateConfig,
getManagerConfig,
mergeChildConfig,
} from '../../../config';
import { getDefaultConfig } from '../../../datasource';
import { logger } from '../../../logger';
import { getPackageUpdates } from '../../../manager';
import { PackageDependency, PackageFile } from '../../../manager/common';
import { SkipReason } from '../../../types';
import { clone } from '../../../util/clone';
import { applyPackageRules } from '../../../util/package-rules';
import { LookupUpdateConfig, lookupUpdates } from './lookup';
async function fetchDepUpdates(
packageFileConfig: ManagerConfig & PackageFile,
indep: PackageDependency
): Promise<PackageDependency> {
const dep = clone(indep);
dep.updates = [];
if (dep.skipReason) {
return dep;
}
const { manager, packageFile } = packageFileConfig;
const { depName, currentValue } = dep;
// TODO: fix types
let depConfig = mergeChildConfig(packageFileConfig, dep);
const datasourceDefaultConfig = await getDefaultConfig(depConfig.datasource);
depConfig = mergeChildConfig(depConfig, datasourceDefaultConfig);
depConfig = applyPackageRules(depConfig);
if (depConfig.ignoreDeps.includes(depName)) {
logger.debug({ dependency: dep.depName }, 'Dependency is ignored');
dep.skipReason = SkipReason.Ignored;
} else if (depConfig.internalPackages?.includes(depName)) {
// istanbul ignore next
dep.skipReason = SkipReason.InternalPackage;
} else if (depConfig.enabled === false) {
logger.debug({ dependency: dep.depName }, 'Dependency is disabled');
dep.skipReason = SkipReason.Disabled;
} else {
if (depConfig.datasource) {
Object.assign(dep, await lookupUpdates(depConfig as LookupUpdateConfig));
} else {
dep.updates = await getPackageUpdates(manager, depConfig);
}
dep.updates = dep.updates || [];
// istanbul ignore if
if (dep.updates.length) {
logger.trace(
{ dependency: depName },
`${dep.updates.length} result(s): ${dep.updates.map(
(upgrade) => upgrade.newValue
)}`
);
}
logger.trace({
packageFile,
manager,
depName,
currentValue,
updates: dep.updates,
});
}
return dep;
}
async function fetchManagerPackagerFileUpdates(
config: RenovateConfig,
managerConfig: ManagerConfig,
pFile: PackageFile
): Promise<void> {
const { packageFile } = pFile;
const packageFileConfig = mergeChildConfig(managerConfig, pFile);
const { manager } = packageFileConfig;
const queue = pFile.deps.map((dep) => (): Promise<PackageDependency> =>
fetchDepUpdates(packageFileConfig, dep)
);
logger.trace(
{ manager, packageFile, queueLength: queue.length },
'fetchManagerPackagerFileUpdates starting with concurrency'
);
// eslint-disable-next-line no-param-reassign
pFile.deps = await pAll(queue, { concurrency: 5 });
logger.trace({ packageFile }, 'fetchManagerPackagerFileUpdates finished');
}
async function fetchManagerUpdates(
config: RenovateConfig,
packageFiles: Record<string, PackageFile[]>,
manager: string
): Promise<void> {
const managerConfig = getManagerConfig(config, manager);
const queue = packageFiles[manager].map((pFile) => (): Promise<void> =>
fetchManagerPackagerFileUpdates(config, managerConfig, pFile)
);
logger.trace(
{ manager, queueLength: queue.length },
'fetchManagerUpdates starting'
);
await pAll(queue, { concurrency: 5 });
logger.trace({ manager }, 'fetchManagerUpdates finished');
}
export async function fetchUpdates(
config: RenovateConfig,
packageFiles: Record<string, PackageFile[]>
): Promise<void> {
const managers = Object.keys(packageFiles);
const allManagerJobs = managers.map((manager) =>
fetchManagerUpdates(config, packageFiles, manager)
);
await Promise.all(allManagerJobs);
logger.debug(
{ baseBranch: config.baseBranch },
'Package releases lookups complete'
);
}