Skip to content

Commit

Permalink
[patch] adding configuration parameters for digger plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Aug 2, 2024
1 parent dfbc5c9 commit 62cb49c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.zegreatrob.tools.digger.core

import com.zegreatrob.tools.digger.model.Contribution

fun List<CommitRef>.contribution(): Contribution {
fun MessageDigger.contribution(commitRefs: List<CommitRef>): Contribution {
val messageDigResults =
map { commit ->
commit.commitInspectionResult(MessageDigger().digIntoMessage(commit.fullMessage))
commitRefs.map { commit ->
commit.commitInspectionResult(digIntoMessage(commit.fullMessage))
}

val lastCommit = firstOrNull()
val firstCommit = lastOrNull()
val lastCommit = commitRefs.firstOrNull()
val firstCommit = commitRefs.lastOrNull()
return Contribution(
lastCommit = lastCommit?.id ?: "",
firstCommit = firstCommit?.id ?: "",
Expand All @@ -22,7 +22,7 @@ fun List<CommitRef>.contribution(): Contribution {
label = null,
tagName = null,
tagDateTime = null,
commitCount = count(),
commitCount = commitRefs.count(),
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.zegreatrob.tools.digger.core

@Suppress("RegExpRedundantEscape")
class MessageDigger(
majorRegex: Regex = Regex("\\[major\\]"),
minorRegex: Regex = Regex("\\[minor\\]"),
patchRegex: Regex = Regex("\\[patch\\]"),
noneRegex: Regex = Regex("\\[none\\]"),
storyIdRegex: Regex = Regex("\\[(?<storyId>.*?)\\]"),
easeRegex: Regex = Regex("-(?<ease>[1-5])-"),
majorRegex: Regex = Defaults.majorRegex,
minorRegex: Regex = Defaults.minorRegex,
patchRegex: Regex = Defaults.patchRegex,
noneRegex: Regex = Defaults.noneRegex,
storyIdRegex: Regex = Defaults.storyIdRegex,
easeRegex: Regex = Defaults.easeRegex,
) {
init {
if (!storyIdRegex.pattern.contains("?<storyId>")) {
Expand All @@ -18,6 +17,16 @@ class MessageDigger(
}
}

@Suppress("RegExpRedundantEscape")
object Defaults {
val majorRegex = Regex("\\[major\\]")
val minorRegex = Regex("\\[minor\\]")
val patchRegex = Regex("\\[patch\\]")
val noneRegex = Regex("\\[none\\]")
val storyIdRegex = Regex("\\[(?<storyId>.*?)\\]")
val easeRegex = Regex("-(?<ease>[1-5])-")
}

private val regexes =
mapOf(
"major" to majorRegex,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.zegreatrob.tools.digger

import com.zegreatrob.tools.digger.core.DiggerGitWrapper
import com.zegreatrob.tools.digger.core.MessageDigger
import com.zegreatrob.tools.digger.core.TagRef
import com.zegreatrob.tools.digger.core.allContributionCommits
import com.zegreatrob.tools.digger.core.contribution
Expand All @@ -19,17 +20,43 @@ open class DiggerExtension(objectFactory: ObjectFactory) {
@Input
var workingDirectory = objectFactory.property<File>()

@Input
var majorRegex = objectFactory.property<Regex>().convention(MessageDigger.Defaults.majorRegex)

@Input
var minorRegex = objectFactory.property<Regex>().convention(MessageDigger.Defaults.minorRegex)

@Input
var patchRegex = objectFactory.property<Regex>().convention(MessageDigger.Defaults.patchRegex)

@Input
var noneRegex = objectFactory.property<Regex>().convention(MessageDigger.Defaults.noneRegex)

@Input
var storyIdRegex = objectFactory.property<Regex>().convention(MessageDigger.Defaults.storyIdRegex)

@Input
var easeRegex = objectFactory.property<Regex>().convention(MessageDigger.Defaults.easeRegex)

private val gitDigger get() = DiggerGitWrapper(workingDirectory.get().absolutePath)
private val messageDigger
get() = MessageDigger(
majorRegex = majorRegex.get(),
minorRegex = minorRegex.get(),
patchRegex = patchRegex.get(),
noneRegex = noneRegex.get(),
storyIdRegex = storyIdRegex.get(),
easeRegex = easeRegex.get(),
)

fun allContributionData() = gitDigger
.allContributionCommits()
.map { range -> range.first to range.second.toList().contribution() }
.map { range -> range.first to messageDigger.contribution(range.second.toList()) }
.map { (tag, contributions) -> contributions.copyWithLabelAndTag(tag) }

fun currentContributionData() =
with(gitDigger) {
currentContributionCommits()
.contribution()
messageDigger.contribution(currentContributionCommits())
.copyWithLabelAndTag(currentCommitTag())
}

Expand Down

0 comments on commit 62cb49c

Please sign in to comment.