From 6f574b316f3bdb47ea780c6d01abf74266de8705 Mon Sep 17 00:00:00 2001 From: RoB Murdock Date: Thu, 14 Sep 2023 22:41:10 -0400 Subject: [PATCH] [patch] adding label to contributions from digger, which defaults to the project name --- .../com/zegreatrob/tools/digger/core/Contribution.kt | 5 +++-- .../tools/digger/json/ContributionDataJson.kt | 3 +++ .../tools/digger/json/ContributionParserTest.kt | 1 + .../zegreatrob/tools/digger/model/Contribution.kt | 1 + .../tools/digger/DiggerPluginFunctionalTest.kt | 12 ++++++++++++ .../kotlin/com/zegreatrob/tools/digger.gradle.kts | 2 ++ .../com/zegreatrob/tools/digger/DiggerExtension.kt | 9 +++++++++ 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tools/digger-core/src/main/kotlin/com/zegreatrob/tools/digger/core/Contribution.kt b/tools/digger-core/src/main/kotlin/com/zegreatrob/tools/digger/core/Contribution.kt index b9a04b7..75cfb15 100644 --- a/tools/digger-core/src/main/kotlin/com/zegreatrob/tools/digger/core/Contribution.kt +++ b/tools/digger-core/src/main/kotlin/com/zegreatrob/tools/digger/core/Contribution.kt @@ -10,14 +10,14 @@ fun List.contribution(): Contribution { } return Contribution( - firstCommit = lastOrNull()?.id ?: "", lastCommit = firstOrNull()?.id ?: "", - dateTime = firstOrNull()?.dateTime?.toInstant()?.toKotlinInstant(), + firstCommit = lastOrNull()?.id ?: "", authors = messageDigResults.flatMap { it.authors } .map { it.lowercase() } .toSet() .sorted() .toList(), + dateTime = firstOrNull()?.dateTime?.toInstant()?.toKotlinInstant(), ease = messageDigResults.mapNotNull { it.ease }.maxOrNull(), storyId = messageDigResults.mapNotNull { it.storyId } .let { @@ -28,6 +28,7 @@ fun List.contribution(): Contribution { } }, semver = messageDigResults.mapNotNull { it.semver }.highestPrioritySemver()?.toString(), + label = null, ) } diff --git a/tools/digger-json/src/commonMain/kotlin/com/zegreatrob/tools/digger/json/ContributionDataJson.kt b/tools/digger-json/src/commonMain/kotlin/com/zegreatrob/tools/digger/json/ContributionDataJson.kt index 25d9769..6d9aa3a 100644 --- a/tools/digger-json/src/commonMain/kotlin/com/zegreatrob/tools/digger/json/ContributionDataJson.kt +++ b/tools/digger-json/src/commonMain/kotlin/com/zegreatrob/tools/digger/json/ContributionDataJson.kt @@ -15,6 +15,7 @@ internal data class ContributionJson( val ease: Int?, val storyId: String?, val semver: String?, + val label: String?, ) fun Iterable.toJsonString(): String = Json.encodeToString(map(Contribution::toJsonModel)) @@ -37,6 +38,7 @@ private fun Contribution.toJsonModel() = ContributionJson( ease = ease, storyId = storyId, semver = semver, + label = label, ) private fun ContributionJson.toModel() = Contribution( @@ -47,4 +49,5 @@ private fun ContributionJson.toModel() = Contribution( ease = ease, storyId = storyId, semver = semver, + label = label, ) diff --git a/tools/digger-json/src/commonTest/kotlin/com/zegreatrob/tools/digger/json/ContributionParserTest.kt b/tools/digger-json/src/commonTest/kotlin/com/zegreatrob/tools/digger/json/ContributionParserTest.kt index 20e679b..890b4d5 100644 --- a/tools/digger-json/src/commonTest/kotlin/com/zegreatrob/tools/digger/json/ContributionParserTest.kt +++ b/tools/digger-json/src/commonTest/kotlin/com/zegreatrob/tools/digger/json/ContributionParserTest.kt @@ -36,5 +36,6 @@ class ContributionParserTest { ease = Random.nextInt(), storyId = "${uuid4()}", semver = "${uuid4()}", + label = "${uuid4()}", ) } diff --git a/tools/digger-model/src/commonMain/kotlin/com/zegreatrob/tools/digger/model/Contribution.kt b/tools/digger-model/src/commonMain/kotlin/com/zegreatrob/tools/digger/model/Contribution.kt index fb5b66e..6ac329f 100644 --- a/tools/digger-model/src/commonMain/kotlin/com/zegreatrob/tools/digger/model/Contribution.kt +++ b/tools/digger-model/src/commonMain/kotlin/com/zegreatrob/tools/digger/model/Contribution.kt @@ -10,4 +10,5 @@ data class Contribution( val ease: Int?, val storyId: String?, val semver: String?, + val label: String?, ) diff --git a/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/DiggerPluginFunctionalTest.kt b/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/DiggerPluginFunctionalTest.kt index 43eba17..e3ac5fa 100644 --- a/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/DiggerPluginFunctionalTest.kt +++ b/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/DiggerPluginFunctionalTest.kt @@ -359,6 +359,7 @@ class DiggerPluginFunctionalTest { "ease" to null, "storyId" to null, "semver" to null, + "label" to projectDir.name, ), mapOf( "lastCommit" to firstCommit.id, @@ -373,6 +374,7 @@ class DiggerPluginFunctionalTest { "ease" to null, "storyId" to null, "semver" to null, + "label" to projectDir.name, ), ), parseAll(allOutput.readText()), @@ -416,6 +418,7 @@ class DiggerPluginFunctionalTest { "ease" to 3, "storyId" to null, "semver" to null, + "label" to projectDir.name, ), mapOf( "authors" to listOf("funk@test.io", "test@funk.edu"), @@ -425,6 +428,7 @@ class DiggerPluginFunctionalTest { "ease" to 4, "storyId" to null, "semver" to null, + "label" to projectDir.name, ), ), parseAll(allOutput.readText()), @@ -460,6 +464,7 @@ class DiggerPluginFunctionalTest { "ease" to 3, "storyId" to "DOGCOW-18", "semver" to null, + "label" to projectDir.name, ), mapOf( "authors" to listOf("funk@test.io", "test@funk.edu"), @@ -469,6 +474,7 @@ class DiggerPluginFunctionalTest { "ease" to null, "storyId" to "DOGCOW-17", "semver" to null, + "label" to projectDir.name, ), ), parseAll(allOutput.readText()), @@ -503,6 +509,7 @@ class DiggerPluginFunctionalTest { "ease" to 3, "storyId" to "DOGCOW-17", "semver" to null, + "label" to projectDir.name, ), ), parseAll(allOutput.readText()), @@ -516,6 +523,9 @@ class DiggerPluginFunctionalTest { plugins { id("com.zegreatrob.tools.digger") } + digger { + label.set("AwesomeProject") + } """.trimIndent(), ) val grgit = initializeGitRepo(listOf("[DOGCOW-17] here's a message")) @@ -539,6 +549,7 @@ class DiggerPluginFunctionalTest { "ease" to 3, "storyId" to "DOGCOW-17, DOGCOW-18", "semver" to null, + "label" to "AwesomeProject", ), ), parseAll(allOutput.readText()), @@ -581,6 +592,7 @@ class DiggerPluginFunctionalTest { "firstCommit" to firstCommit.id, "ease" to 4, "storyId" to null, + "label" to projectDir.name, ), ), parseAll(allOutput.readText()), diff --git a/tools/digger-plugin/src/main/kotlin/com/zegreatrob/tools/digger.gradle.kts b/tools/digger-plugin/src/main/kotlin/com/zegreatrob/tools/digger.gradle.kts index 8963e5b..2b3bba8 100644 --- a/tools/digger-plugin/src/main/kotlin/com/zegreatrob/tools/digger.gradle.kts +++ b/tools/digger-plugin/src/main/kotlin/com/zegreatrob/tools/digger.gradle.kts @@ -12,6 +12,8 @@ plugins { val digger = project.extensions.create("digger", DiggerExtension::class, grgitService) +digger.label.convention(project.name) + val exportToGithub = project.findProperty("exportToGithub") val diggerBuildDirectory: Provider = layout.buildDirectory.dir("digger") diff --git a/tools/digger-plugin/src/main/kotlin/com/zegreatrob/tools/digger/DiggerExtension.kt b/tools/digger-plugin/src/main/kotlin/com/zegreatrob/tools/digger/DiggerExtension.kt index 6c3f177..e5b0dfc 100644 --- a/tools/digger-plugin/src/main/kotlin/com/zegreatrob/tools/digger/DiggerExtension.kt +++ b/tools/digger-plugin/src/main/kotlin/com/zegreatrob/tools/digger/DiggerExtension.kt @@ -4,18 +4,27 @@ import com.zegreatrob.tools.digger.core.allContributionCommits import com.zegreatrob.tools.digger.core.contribution import com.zegreatrob.tools.digger.core.currentContributionCommits import org.ajoberstar.grgit.gradle.GrgitServiceExtension +import org.gradle.api.model.ObjectFactory +import org.gradle.api.tasks.Input +import org.gradle.kotlin.dsl.property open class DiggerExtension( private val grgitServiceExtension: GrgitServiceExtension, + objectFactory: ObjectFactory, ) { + @Input + var label = objectFactory.property() + fun allContributionData() = grgitServiceExtension.service.get().grgit .allContributionCommits() .map { range -> range.toList().contribution() } + .map { it.copy(label = label.get()) } fun currentContributionData() = grgitServiceExtension.service.get().grgit .currentContributionCommits() .contribution() + .copy(label = label.get()) fun headId(): String = grgitServiceExtension.service.get().grgit.head().id }