Skip to content

Commit

Permalink
[patch] refactoring current contribution data
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Aug 10, 2024
1 parent 5d3b759 commit e53f499
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 39 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
package com.zegreatrob.tools.digger.core

fun DiggerGitWrapper.currentContributionCommits(): List<CommitRef> {
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<CommitRef> = if (previousTag == null) {
log()
} else {
logWithRange(previousTag.name, "HEAD")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<TagRef>,
) = 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()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TagRef> {
val outputText = runProcess(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e53f499

Please sign in to comment.