-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (69 loc) · 2.43 KB
/
index.js
File metadata and controls
76 lines (69 loc) · 2.43 KB
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
import { fileURLToPath } from "node:url";
import { readFile } from "node:fs/promises";
import { Octokit } from "@octokit/rest";
import { throttling } from "@octokit/plugin-throttling";
import GitHubIssueOnboarderRepository from "./src/github/GitHubIssueOnboarderRepository.js";
import RosterMemberRepository from "./src/roster/RosterMemberRepository.js";
import CommitRepository from "./src/commit/CommitRepository.js";
import MeanTimeToFirstCommitCalculator from "./src/MeanTimeToFirstCommitCalculator.js";
/* node:coverage disable */
const throttledOctokit = () => {
const ThrottledOctokit = Octokit.plugin(throttling);
return new ThrottledOctokit({
auth: process.env.GITHUB_TOKEN,
throttle: {
onRateLimit: (retryAfter, { method, url }, octokit) => {
octokit.log.warn(
`Request quota exhausted for request ${method} ${url}, retrying after ${retryAfter}`,
);
return true;
},
onSecondaryRateLimit: (retryAfter, { method, url }, octokit) => {
octokit.log.warn(
`SecondaryRateLimit detected for request ${method} ${url}, retrying after ${retryAfter}`,
);
return true;
},
},
});
};
/* node:coverage enable */
export const main = (roster) => {
const octokit = throttledOctokit();
const gitHubIssueOnboarderRepository = new GitHubIssueOnboarderRepository(
octokit,
);
const rosterMemberRepository = new RosterMemberRepository(roster);
const commitRepository = new CommitRepository(octokit);
return Promise.all([
calculateMeanTimeToFirstCommit(
"Mean Time to First Commit based on GitHub Onboarding Issues (days)",
gitHubIssueOnboarderRepository,
commitRepository,
),
calculateMeanTimeToFirstCommit(
"Mean Time to First Commit based on Roster (days)",
rosterMemberRepository,
commitRepository,
),
]);
};
const calculateMeanTimeToFirstCommit = async (
label,
onboarderRepository,
commitRepository,
) => {
const meanTimeToFirstCommitCalculator = new MeanTimeToFirstCommitCalculator(
onboarderRepository,
commitRepository,
);
const meanTimeToFirstCommit =
await meanTimeToFirstCommitCalculator.calculate();
console.log(`${label}: ${meanTimeToFirstCommit.toFixed(2)}`);
};
/* node:coverage disable */
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const roster = JSON.parse(await readFile("./src/roster/roster.json"));
await main(roster);
}
/* node:coverage enable */