diff --git a/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/CurrentCommitTag.kt b/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/CurrentCommitTag.kt deleted file mode 100644 index 6be321f..0000000 --- a/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/CurrentCommitTag.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.zegreatrob.tools.digger.core - -fun DiggerGitWrapper.currentCommitTag(): TagRef? = findRelatedTag(headCommitId()) - -private fun DiggerGitWrapper.findRelatedTag(headCommitId: String): TagRef? = listTags() - .find { it.commitId == headCommitId } diff --git a/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/CurrentContributionCommits.kt b/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/CurrentContributionCommits.kt index 6f6a89e..0827d2a 100644 --- a/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/CurrentContributionCommits.kt +++ b/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/CurrentContributionCommits.kt @@ -1,20 +1,7 @@ package com.zegreatrob.tools.digger.core -fun DiggerGitWrapper.currentContributionCommits(): List { - val tag = previousTag() - return if (tag == null) { - log() - } else { - return logWithRange(tag.name, "HEAD") - } -} - -private fun DiggerGitWrapper.previousTag(): TagRef? { - val tagList = listTags().sortedByDescending { it.dateTime } - val tag = tagList.firstOrNull() - return if (tag?.commitId == headCommitId()) { - tagList.getOrNull(1) - } else { - tag - } +fun DiggerGitWrapper.currentContributionCommits(previousTag: TagRef?): List = if (previousTag == null) { + log() +} else { + logWithRange(previousTag.name, "HEAD") } diff --git a/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/DiggerCore.kt b/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/DiggerCore.kt index 138b333..3ba11db 100644 --- a/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/DiggerCore.kt +++ b/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/DiggerCore.kt @@ -7,15 +7,29 @@ class DiggerCore( ) { fun currentContributionData() = with(gitWrapper) { - val currentCommitTag = currentCommitTag() - messageDigger.contribution(currentContributionCommits()) + val (currentTag, previousTag) = currentRelevantTags( + headCommitId = headCommitId(), + lastTwoTags = listTags().take(2), + ) + messageDigger.contribution(currentContributionCommits(previousTag)) .copy( label = label, - tagName = currentCommitTag?.name, - tagDateTime = currentCommitTag?.dateTime, + tagName = currentTag?.name, + tagDateTime = currentTag?.dateTime, ) } + private fun currentRelevantTags( + headCommitId: String, + lastTwoTags: List, + ) = lastTwoTags.getOrNull(0).let { latestTag -> + if (latestTag?.commitId == headCommitId) { + latestTag to lastTwoTags.getOrNull(1) + } else { + null to latestTag + } + } + fun allContributionData() = gitWrapper .allContributionCommits() .map { range -> range.first to messageDigger.contribution(range.second.toList()) } diff --git a/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/DiggerGitWrapper.kt b/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/DiggerGitWrapper.kt index 4f54dbf..af9ad45 100644 --- a/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/DiggerGitWrapper.kt +++ b/tools/digger-core/src/commonMain/kotlin/com/zegreatrob/tools/digger/core/DiggerGitWrapper.kt @@ -4,18 +4,15 @@ import kotlinx.datetime.Instant class DiggerGitWrapper(private val workingDirectory: String) { - fun headCommitId(): String { - val outputText = runProcess( - listOf( - "git", - "--no-pager", - "rev-parse", - "HEAD", - ), - workingDirectory, - ) - return outputText.trim() - } + fun headCommitId(): String = runProcess( + listOf( + "git", + "--no-pager", + "rev-parse", + "HEAD", + ), + workingDirectory, + ).trim() fun listTags(): List { val outputText = runProcess( diff --git a/tools/digger-test/src/jvmMain/kotlin/com/zegreatrob/tools/digger/CurrentContributionTestSpec.kt b/tools/digger-test/src/jvmMain/kotlin/com/zegreatrob/tools/digger/CurrentContributionTestSpec.kt index bac6949..6ea0837 100644 --- a/tools/digger-test/src/jvmMain/kotlin/com/zegreatrob/tools/digger/CurrentContributionTestSpec.kt +++ b/tools/digger-test/src/jvmMain/kotlin/com/zegreatrob/tools/digger/CurrentContributionTestSpec.kt @@ -410,6 +410,7 @@ interface CurrentContributionTestSpec : SetupWithOverrides { grgit.addCommitWithMessage("sixth") val merge2Commit = grgit.mergeInBranch("branch1", "merge2") + delayLongEnoughToAffectGitDate() val thirdRelease = grgit.addTag("release3") val allOutput = runCurrentContributionData()