Skip to content
This repository was archived by the owner on Jul 5, 2025. It is now read-only.

Commit 735bf1d

Browse files
authored
Merge e5c085c into 2339d57
2 parents 2339d57 + e5c085c commit 735bf1d

26 files changed

+1002
-58
lines changed

build.gradle.kts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ kotlin {
6161
}
6262

6363
val commonTest by getting {
64-
dependsOn(commonMain)
6564
dependencies {
6665
implementation(kotlin("test"))
6766
implementation("com.squareup.okio:okio-fakefilesystem:3.4.+")
6867
implementation("com.willowtreeapps.assertk:assertk:0.+")
6968
}
7069
}
7170

71+
// used by the 'getting' delegate
72+
@Suppress("UNUSED_VARIABLE", "KotlinRedundantDiagnosticSuppress")
7273
val jvmMain by getting {
7374
dependsOn(commonMain)
7475
dependencies {
@@ -79,12 +80,14 @@ kotlin {
7980
}
8081
}
8182

82-
@Suppress("UNUSED_VARIABLE", "KotlinRedundantDiagnosticSuppress") // used by the 'getting' delegate
83+
// used by the 'getting' delegate
84+
@Suppress("UNUSED_VARIABLE", "KotlinRedundantDiagnosticSuppress")
8385
val jvmTest by getting {
8486
dependsOn(commonTest)
85-
dependsOn(jvmMain)
8687
}
8788

89+
// used by the 'getting' delegate
90+
@Suppress("UNUSED_VARIABLE", "KotlinRedundantDiagnosticSuppress")
8891
val macNativeMain by getting {
8992
dependsOn(commonMain)
9093
dependencies {
@@ -93,10 +96,10 @@ kotlin {
9396
}
9497
}
9598

96-
@Suppress("UNUSED_VARIABLE", "KotlinRedundantDiagnosticSuppress") // used by the 'getting' delegate
99+
// used by the 'getting' delegate
100+
@Suppress("UNUSED_VARIABLE", "KotlinRedundantDiagnosticSuppress")
97101
val macNativeTest by getting {
98102
dependsOn(commonTest)
99-
dependsOn(macNativeMain)
100103
}
101104

102105
}
@@ -120,6 +123,7 @@ kotlin {
120123
jvmMainCompilation.output.allOutputs,
121124
)
122125
)
126+
standardInput = System.`in`
123127
}
124128

125129
// make the JVM 'jar' task work

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Language properties
22
kotlin.code.style=official
33
kotlin.mpp.enableCInteropCommonization=true
4+
kotlin.mpp.applyDefaultHierarchyTemplate=false
45

56
# Engine properties
67
org.gradle.jvmargs=-Xmx4096m
78

89
# Project properties
910
config.group = xyz.marinkovic.milos
1011
config.artifact = codestats
11-
config.version = 0.4.0
12+
config.version = 0.5.0
1213
config.gitHubRepoOwner = milosmns
1314
config.gitHubRepoName = code-stats

src/commonMain/kotlin/Main.kt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import calculator.di.provideGenericLongMetricCalculators
22
import components.data.TeamHistoryConfig
33
import history.TeamHistory
4+
import history.filter.transform.RepositoryDateTransform
45
import history.github.di.provideGitHubHistory
56
import history.github.di.provideGitHubHistoryConfig
67
import history.storage.di.provideStoredHistory
78
import kotlinx.coroutines.runBlocking
9+
import kotlinx.datetime.LocalDate
810
import utils.fromFile
911

1012
fun main(): Unit = runBlocking {
13+
/*************************************************************************
14+
THESE ARE TEMPORARY EXPERIMENTS, NOT PART OF THE FINAL PRODUCT
15+
*************************************************************************/
16+
1117
println("\n== Code Stats CLI ==\n")
1218

1319
print("Loading configuration... ")
@@ -58,16 +64,31 @@ fun main(): Unit = runBlocking {
5864
)
5965
}
6066

61-
stored.forEachIndexed { i, repo ->
62-
println("\n== Repository #$i ==")
67+
stored.forEach { repo ->
6368
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+
}
6475
println("-- ${repo.fullName} --\n")
6576
}
6677

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+
6789
// OTHER EXPERIMENTS
6890
provideGenericLongMetricCalculators().forEach {
69-
val metric = it.calculate(stored)
70-
println("\n== ${metric.name} ==")
91+
val metric = it.calculate(filtered)
7192
println(metric.simpleFormat)
7293
println("-- ${metric.name} --\n")
7394
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package history.filter.predicate
2+
3+
import components.data.CodeReviewComment
4+
import kotlinx.datetime.LocalDate
5+
6+
class CodeReviewCommentIsBetween(
7+
private val startDateInclusive: LocalDate,
8+
private val endDateInclusive: LocalDate? = null,
9+
) : (CodeReviewComment) -> Boolean {
10+
override fun invoke(subject: CodeReviewComment) =
11+
subject.createdAt.isBetween(startDateInclusive, endDateInclusive)
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package history.filter.predicate
2+
3+
import components.data.CodeReviewFeedback
4+
import kotlinx.datetime.LocalDate
5+
6+
class CodeReviewFeedbackIsBetween(
7+
private val startDateInclusive: LocalDate,
8+
private val endDateInclusive: LocalDate? = null,
9+
) : (CodeReviewFeedback) -> Boolean {
10+
override fun invoke(subject: CodeReviewFeedback) =
11+
subject.submittedAt?.isBetween(startDateInclusive, endDateInclusive) == true
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package history.filter.predicate
2+
3+
import components.data.CodeReview
4+
import kotlinx.datetime.LocalDate
5+
6+
class CodeReviewIsBetween(
7+
private val startDateInclusive: LocalDate,
8+
private val endDateInclusive: LocalDate? = null,
9+
) : (CodeReview) -> Boolean {
10+
override fun invoke(subject: CodeReview): Boolean {
11+
val isMergedOnTime = when {
12+
endDateInclusive == null -> true
13+
subject.mergedAt == null -> false
14+
else -> subject.mergedAt.date <= endDateInclusive
15+
}
16+
val isClosedOnTime = when {
17+
endDateInclusive == null -> true
18+
subject.closedAt == null -> false
19+
else -> subject.closedAt.date <= endDateInclusive
20+
}
21+
val isFinishedOnTime = when {
22+
subject.mergedAt != null && subject.closedAt == null -> isMergedOnTime
23+
subject.mergedAt == null && subject.closedAt != null -> isClosedOnTime
24+
subject.mergedAt != null && subject.closedAt != null -> isMergedOnTime && isClosedOnTime
25+
else -> isMergedOnTime || isClosedOnTime
26+
}
27+
val isCreatedBetween = subject.createdAt.isBetween(startDateInclusive, endDateInclusive)
28+
return isFinishedOnTime && isCreatedBetween
29+
}
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package history.filter.predicate
2+
3+
import components.data.DiscussionComment
4+
import kotlinx.datetime.LocalDate
5+
6+
class DiscussionCommentIsBetween(
7+
private val startDateInclusive: LocalDate,
8+
private val endDateInclusive: LocalDate? = null,
9+
) : (DiscussionComment) -> Boolean {
10+
override fun invoke(subject: DiscussionComment) =
11+
subject.createdAt.isBetween(startDateInclusive, endDateInclusive)
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package history.filter.predicate
2+
3+
import components.data.Discussion
4+
import kotlinx.datetime.LocalDate
5+
6+
class DiscussionIsBetween(
7+
private val startDateInclusive: LocalDate,
8+
private val endDateInclusive: LocalDate? = null,
9+
) : (Discussion) -> Boolean {
10+
override fun invoke(subject: Discussion): Boolean {
11+
val isClosedOnTime = when {
12+
endDateInclusive == null -> true
13+
subject.closedAt == null -> false
14+
else -> subject.closedAt.date <= endDateInclusive
15+
}
16+
val isCreatedBetween = subject.createdAt.isBetween(startDateInclusive, endDateInclusive)
17+
return isClosedOnTime && isCreatedBetween
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package history.filter.predicate
2+
3+
import kotlinx.datetime.LocalDate
4+
import kotlinx.datetime.LocalDateTime
5+
6+
fun LocalDateTime.isBetween(
7+
startDateInclusive: LocalDate,
8+
endDateInclusive: LocalDate? = null,
9+
) = when {
10+
date < startDateInclusive -> false
11+
endDateInclusive != null && date > endDateInclusive -> false
12+
else -> true
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package history.filter.transform
2+
3+
import components.data.CodeReview
4+
import history.filter.predicate.CodeReviewCommentIsBetween
5+
import history.filter.predicate.CodeReviewFeedbackIsBetween
6+
import kotlinx.datetime.LocalDate
7+
8+
class CodeReviewDateTransform(
9+
private val openDateInclusive: LocalDate,
10+
private val closeDateInclusive: LocalDate? = null,
11+
) : (CodeReview) -> CodeReview {
12+
override fun invoke(subject: CodeReview) = subject.copy(
13+
comments = subject.comments.filter(CodeReviewCommentIsBetween(openDateInclusive, closeDateInclusive)),
14+
feedbacks = subject.feedbacks.filter(CodeReviewFeedbackIsBetween(openDateInclusive, closeDateInclusive)),
15+
)
16+
}

0 commit comments

Comments
 (0)