|
1 | | -import calculator.di.provideGenericLongMetricCalculators |
| 1 | +import commands.CommandLineArguments |
| 2 | +import commands.CommandLineArguments.Mode.FETCH |
| 3 | +import commands.CommandLineArguments.Mode.PRINT |
| 4 | +import commands.CommandLineArguments.Mode.PURGE |
| 5 | +import commands.CommandLineArguments.Mode.REPORT |
| 6 | +import commands.CommandLineArguments.Mode.SERVE |
| 7 | +import commands.di.provideFetchCommand |
| 8 | +import commands.di.providePrintCommand |
| 9 | +import commands.di.providePurgeCommand |
| 10 | +import commands.di.provideReportCommand |
| 11 | +import commands.di.provideServeCommand |
2 | 12 | import components.data.TeamHistoryConfig |
3 | | -import history.TeamHistory |
4 | | -import history.filter.transform.RepositoryDateTransform |
5 | | -import history.github.di.provideGitHubHistory |
6 | | -import history.github.di.provideGitHubHistoryConfig |
7 | | -import history.storage.di.provideStoredHistory |
8 | | -import kotlinx.coroutines.runBlocking |
9 | | -import kotlinx.datetime.LocalDate |
10 | 13 | import utils.fromFile |
11 | 14 |
|
12 | | -fun main(): Unit = runBlocking { |
13 | | - /************************************************************************* |
14 | | - THESE ARE TEMPORARY EXPERIMENTS, NOT PART OF THE FINAL PRODUCT |
15 | | - *************************************************************************/ |
16 | | - |
17 | | - println("\n== Code Stats CLI ==\n") |
18 | | - |
19 | | - print("Loading configuration... ") |
20 | | - val teamHistoryConfig = TeamHistoryConfig.fromFile("src/commonMain/resources/sample.config.yaml") |
21 | | - println("Done.") |
22 | | - |
23 | | - println(teamHistoryConfig.simpleFormat) |
24 | | - |
25 | | - val history: TeamHistory = provideGitHubHistory( |
26 | | - teamHistoryConfig = teamHistoryConfig, |
27 | | - gitHubHistoryConfig = provideGitHubHistoryConfig(), |
28 | | - ) |
29 | | - |
30 | | - try { |
31 | | - // NETWORK EXPERIMENTS |
32 | | -// println("Loading team history...") |
33 | | -// val fetched = mutableListOf<Repository>() |
34 | | -// teamHistoryConfig.teams.forEach { team -> |
35 | | -// println("Loading for team ${team.title}...") |
36 | | -// team.discussionRepositories.forEach { repoName -> |
37 | | -// println("Loading discussion repository $repoName...") |
38 | | -// fetched += history.fetchRepository(repoName, includeCodeReviews = false, includeDiscussions = true) |
39 | | -// } |
40 | | -// team.codeRepositories.forEach { repoName -> |
41 | | -// println("Loading code repository $repoName...") |
42 | | -// fetched += history.fetchRepository(repoName, includeCodeReviews = true, includeDiscussions = false) |
43 | | -// } |
44 | | -// } |
45 | | - |
46 | | - // STORAGE EXPERIMENTS |
47 | | - val storage = provideStoredHistory(teamHistoryConfig) |
48 | | -// storage.purgeAll() |
49 | | -// val storedUnsorted = mutableListOf<Repository>() |
50 | | -// fetched.forEach { |
51 | | -// storage.storeRepositoryDeep(it) |
52 | | -// storedUnsorted += storage.fetchRepository( |
53 | | -// it.name, |
54 | | -// includeCodeReviews = true, |
55 | | -// includeDiscussions = true, |
56 | | -// ) |
57 | | -// } |
58 | | - |
59 | | - val stored = storage.fetchAllRepositories().map { |
60 | | - storage.fetchRepository( |
61 | | - it.name, |
62 | | - includeCodeReviews = true, |
63 | | - includeDiscussions = true, |
64 | | - ) |
65 | | - } |
66 | | - |
67 | | - stored.forEach { repo -> |
68 | | - println(repo.simpleFormat) |
69 | | - repo.codeReviews.forEach { |
70 | | - println("\t r#${it.number} ${it.createdAt} >> ${it.mergedAt} >> ${it.closedAt}") |
71 | | - } |
72 | | - repo.discussions.forEach { |
73 | | - println("\t d#${it.number} ${it.createdAt} >> ${it.closedAt}") |
74 | | - } |
75 | | - println("-- ${repo.fullName} --\n") |
76 | | - } |
77 | | - |
78 | | - println("Filter by date? DD.MM.YYYY (empty for no filter)") |
79 | | - val dateString = readln().trim() |
80 | | - val filtered = if (dateString.isNotEmpty()) { |
81 | | - val day = dateString.substringBefore(".").toInt() |
82 | | - val month = dateString.substringAfter(".").substringBefore(".").toInt() |
83 | | - val year = dateString.substringAfterLast(".").toInt() |
84 | | - val date = LocalDate(year, month, day) |
85 | | - val transform = RepositoryDateTransform(date, date) |
86 | | - stored.map(transform) |
87 | | - } else stored |
88 | | - |
89 | | - // OTHER EXPERIMENTS |
90 | | - provideGenericLongMetricCalculators().forEach { |
91 | | - val metric = it.calculate(filtered) |
92 | | - println(metric.simpleFormat) |
93 | | - println("-- ${metric.name} --\n") |
94 | | - } |
95 | | - } catch (e: Throwable) { |
96 | | - println("CRITICAL FAILURE! \n\n * ${e.message} * \n\n") |
97 | | - e.printStackTrace() |
98 | | - } finally { |
99 | | - history.close() |
100 | | - } |
101 | | - |
| 15 | +fun main(args: Array<String>) { |
| 16 | + val arguments = CommandLineArguments().load(args) |
| 17 | + val teamHistoryConfig = TeamHistoryConfig.fromFile(arguments.configFile) |
| 18 | + |
| 19 | + when (arguments.mode) { |
| 20 | + SERVE -> provideServeCommand(teamHistoryConfig) |
| 21 | + FETCH -> provideFetchCommand(teamHistoryConfig) |
| 22 | + REPORT -> provideReportCommand(teamHistoryConfig) |
| 23 | + PRINT -> providePrintCommand(teamHistoryConfig) |
| 24 | + PURGE -> providePurgeCommand(teamHistoryConfig) |
| 25 | + }.run() |
102 | 26 | } |
0 commit comments