forked from renovatebot/renovate
/
repository-statistics.ts
152 lines (137 loc) · 3.52 KB
/
repository-statistics.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import type { RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import type { Pr } from '../../../modules/platform';
import { getCache, isCacheModified } from '../../../util/cache/repository';
import type {
BranchCache,
BranchUpgradeCache,
} from '../../../util/cache/repository/types';
import type {
BaseBranchMetadata,
BranchMetadata,
BranchSummary,
} from '../../types';
export function runRenovateRepoStats(
config: RenovateConfig,
prList: Pr[]
): void {
const prStats = { total: 0, open: 0, closed: 0, merged: 0 };
for (const pr of prList) {
if (
pr.title === 'Configure Renovate' ||
pr.title === config.onboardingPrTitle
) {
continue;
}
prStats.total += 1;
switch (pr.state) {
case 'merged':
prStats.merged += 1;
break;
case 'closed':
prStats.closed += 1;
break;
case 'open':
prStats.open += 1;
break;
default:
break;
}
}
logger.debug({ stats: prStats }, `Renovate repository PR statistics`);
}
function branchCacheToMetadata({
automerge,
baseBranch,
baseBranchSha,
branchName,
isModified,
pristine: isPristine,
sha: branchSha,
}: BranchCache): BranchMetadata {
return {
automerge,
baseBranch,
baseBranchSha,
branchName,
branchSha,
isModified,
isPristine,
};
}
function filterDependencyDashboardData(
branches: BranchCache[]
): Partial<BranchCache>[] {
const branchesFiltered: Partial<BranchCache>[] = [];
for (const branch of branches) {
const upgradesFiltered: Partial<BranchUpgradeCache>[] = [];
const { branchName, prNo, prTitle, result, upgrades } = branch;
for (const upgrade of upgrades ?? []) {
const {
datasource,
depName,
displayPending,
fixedVersion,
currentVersion,
currentValue,
newValue,
newVersion,
packageFile,
updateType,
packageName,
} = upgrade;
const filteredUpgrade: Partial<BranchUpgradeCache> = {
datasource,
depName,
displayPending,
fixedVersion,
currentVersion,
currentValue,
newValue,
newVersion,
packageFile,
updateType,
packageName,
};
upgradesFiltered.push(filteredUpgrade);
}
const filteredBranch: Partial<BranchCache> = {
branchName,
prNo,
prTitle,
result,
upgrades: upgradesFiltered,
};
branchesFiltered.push(filteredBranch);
}
return branchesFiltered;
}
export function runBranchSummary(config: RenovateConfig): void {
const defaultBranch = config.defaultBranch;
const { scan, branches } = getCache();
const baseMetadata: BaseBranchMetadata[] = [];
for (const [branchName, cached] of Object.entries(scan ?? {})) {
baseMetadata.push({ branchName, sha: cached.sha });
}
const branchMetadata: BranchMetadata[] = [];
const inactiveBranches: string[] = [];
for (const branch of branches ?? []) {
if (branch.sha) {
branchMetadata.push(branchCacheToMetadata(branch));
} else {
inactiveBranches.push(branch.branchName);
}
}
const res: BranchSummary = {
cacheModified: isCacheModified(),
baseBranches: baseMetadata,
branches: branchMetadata,
defaultBranch,
inactiveBranches,
};
logger.debug(res, 'Branch summary');
if (branches?.length) {
const branchesInformation = filterDependencyDashboardData(branches);
logger.debug({ branchesInformation }, 'branches info extended');
}
}