Skip to content

Commit

Permalink
[patch] adding label to contributions from digger, which defaults to …
Browse files Browse the repository at this point in the history
…the project name
  • Loading branch information
robertfmurdock committed Sep 15, 2023
1 parent c1f2ab8 commit 6f574b3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ fun List<Commit>.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 {
Expand All @@ -28,6 +28,7 @@ fun List<Commit>.contribution(): Contribution {
}
},
semver = messageDigResults.mapNotNull { it.semver }.highestPrioritySemver()?.toString(),
label = null,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal data class ContributionJson(
val ease: Int?,
val storyId: String?,
val semver: String?,
val label: String?,
)

fun Iterable<Contribution>.toJsonString(): String = Json.encodeToString(map(Contribution::toJsonModel))
Expand All @@ -37,6 +38,7 @@ private fun Contribution.toJsonModel() = ContributionJson(
ease = ease,
storyId = storyId,
semver = semver,
label = label,
)

private fun ContributionJson.toModel() = Contribution(
Expand All @@ -47,4 +49,5 @@ private fun ContributionJson.toModel() = Contribution(
ease = ease,
storyId = storyId,
semver = semver,
label = label,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ class ContributionParserTest {
ease = Random.nextInt(),
storyId = "${uuid4()}",
semver = "${uuid4()}",
label = "${uuid4()}",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ data class Contribution(
val ease: Int?,
val storyId: String?,
val semver: String?,
val label: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class DiggerPluginFunctionalTest {
"ease" to null,
"storyId" to null,
"semver" to null,
"label" to projectDir.name,
),
mapOf(
"lastCommit" to firstCommit.id,
Expand All @@ -373,6 +374,7 @@ class DiggerPluginFunctionalTest {
"ease" to null,
"storyId" to null,
"semver" to null,
"label" to projectDir.name,
),
),
parseAll(allOutput.readText()),
Expand Down Expand Up @@ -416,6 +418,7 @@ class DiggerPluginFunctionalTest {
"ease" to 3,
"storyId" to null,
"semver" to null,
"label" to projectDir.name,
),
mapOf(
"authors" to listOf("[email protected]", "[email protected]"),
Expand All @@ -425,6 +428,7 @@ class DiggerPluginFunctionalTest {
"ease" to 4,
"storyId" to null,
"semver" to null,
"label" to projectDir.name,
),
),
parseAll(allOutput.readText()),
Expand Down Expand Up @@ -460,6 +464,7 @@ class DiggerPluginFunctionalTest {
"ease" to 3,
"storyId" to "DOGCOW-18",
"semver" to null,
"label" to projectDir.name,
),
mapOf(
"authors" to listOf("[email protected]", "[email protected]"),
Expand All @@ -469,6 +474,7 @@ class DiggerPluginFunctionalTest {
"ease" to null,
"storyId" to "DOGCOW-17",
"semver" to null,
"label" to projectDir.name,
),
),
parseAll(allOutput.readText()),
Expand Down Expand Up @@ -503,6 +509,7 @@ class DiggerPluginFunctionalTest {
"ease" to 3,
"storyId" to "DOGCOW-17",
"semver" to null,
"label" to projectDir.name,
),
),
parseAll(allOutput.readText()),
Expand All @@ -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"))
Expand All @@ -539,6 +549,7 @@ class DiggerPluginFunctionalTest {
"ease" to 3,
"storyId" to "DOGCOW-17, DOGCOW-18",
"semver" to null,
"label" to "AwesomeProject",
),
),
parseAll(allOutput.readText()),
Expand Down Expand Up @@ -581,6 +592,7 @@ class DiggerPluginFunctionalTest {
"firstCommit" to firstCommit.id,
"ease" to 4,
"storyId" to null,
"label" to projectDir.name,
),
),
parseAll(allOutput.readText()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Directory> = layout.buildDirectory.dir("digger")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>()

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
}

0 comments on commit 6f574b3

Please sign in to comment.