Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes by create-pull-request action #154

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion command-line-tools/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ com-github-ben-manes-versions = "com.github.ben-manes.versions:0.51.0"
nl-littlerobots-version-catalog-update = "nl.littlerobots.version-catalog-update:0.8.5"
org-jetbrains-kotlin-multiplatform = "org.jetbrains.kotlin.multiplatform:2.0.21"
org-jetbrains-kotlin-plugin-serialization = "org.jetbrains.kotlin.plugin.serialization:2.0.21"
org-jmailen-kotlinter = "org.jmailen.kotlinter:4.4.1"
org-jmailen-kotlinter = "org.jmailen.kotlinter:4.5.0"
6 changes: 3 additions & 3 deletions tools-plugins/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[libraries]
com-github-ben-manes-gradle-versions-plugin = "com.github.ben-manes:gradle-versions-plugin:0.51.0"
org-apache-logging-log4j-log4j-core = "org.apache.logging.log4j:log4j-core:2.24.1"
org-jmailen-gradle-kotlinter-gradle = "org.jmailen.gradle:kotlinter-gradle:4.4.1"
org-apache-logging-log4j-log4j-core = "org.apache.logging.log4j:log4j-core:2.24.2"
org-jmailen-gradle-kotlinter-gradle = "org.jmailen.gradle:kotlinter-gradle:4.5.0"

[plugins]
com-github-ben-manes-versions = "com.github.ben-manes.versions:0.51.0"
nl-littlerobots-version-catalog-update = "nl.littlerobots.version-catalog-update:0.8.5"
org-jmailen-kotlinter = "org.jmailen.kotlinter:4.4.1"
org-jmailen-kotlinter = "org.jmailen.kotlinter:4.5.0"
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ fun GitAdapter.sortIntoTagSets(
}
}.filter { it.second.isNotEmpty() }

private fun List<TagRef>.tagPairs(): List<Pair<TagRef?, TagRef?>> =
listOf(Pair(null, firstOrNull())) + mapIndexed { index, commitRef ->
commitRef to getOrNull(index + 1)
}
private fun List<TagRef>.tagPairs(): List<Pair<TagRef?, TagRef?>> = listOf(Pair(null, firstOrNull())) + mapIndexed { index, commitRef ->
commitRef to getOrNull(index + 1)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ private fun mergedStoryIds(messageDigResults: List<CommitInspectionResult>) = me
}
}

private fun CommitRef.commitInspectionResult(digResult: MessageDigResult) =
CommitInspectionResult(
storyId = digResult.storyId,
ease = digResult.ease,
authors = listOf(committerEmail, authorEmail) + digResult.coauthors,
semver = digResult.semver,
)
private fun CommitRef.commitInspectionResult(digResult: MessageDigResult) = CommitInspectionResult(
storyId = digResult.storyId,
ease = digResult.ease,
authors = listOf(committerEmail, authorEmail) + digResult.coauthors,
semver = digResult.semver,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ class DiggerCore(
) {
private fun tagRefs() = gitWrapper.listTags().filter { tagRegex.matches(it.name) }

fun currentContributionData() =
with(gitWrapper) {
val (currentTag, previousTag) = currentRelevantTags(
headCommitId = headCommitId(),
lastTwoTags = tagRefs().take(2),
fun currentContributionData() = with(gitWrapper) {
val (currentTag, previousTag) = currentRelevantTags(
headCommitId = headCommitId(),
lastTwoTags = tagRefs().take(2),
)
messageDigger.contribution(currentContributionCommits(previousTag))
.copy(
label = label,
tagName = currentTag?.name,
tagDateTime = currentTag?.dateTime,
)
messageDigger.contribution(currentContributionCommits(previousTag))
.copy(
label = label,
tagName = currentTag?.name,
tagDateTime = currentTag?.dateTime,
)
}
}

private fun currentRelevantTags(
headCommitId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,22 @@ private fun Regex.cleaned(): String {
}
}

private fun Sequence<MatchResult>.messageDigResult() =
MessageDigResult(
coauthors = mapNotNull { it.groups["coAuthors"]?.value }.toList(),
semver = mapNotNull { getSemver(it) }.maxOrNull(),
storyId = firstNotNullOfOrNull { it.groups["storyId"] }?.value,
ease = firstNotNullOfOrNull { it.groups["ease"] }?.value?.toIntOrNull(),
)
private fun Sequence<MatchResult>.messageDigResult() = MessageDigResult(
coauthors = mapNotNull { it.groups["coAuthors"]?.value }.toList(),
semver = mapNotNull { getSemver(it) }.maxOrNull(),
storyId = firstNotNullOfOrNull { it.groups["storyId"] }?.value,
ease = firstNotNullOfOrNull { it.groups["ease"] }?.value?.toIntOrNull(),
)

private fun getSemver(it: MatchResult) =
when {
it.groupMatches("major") -> SemverType.Major
it.groupMatches("minor") -> SemverType.Minor
it.groupMatches("patch") -> SemverType.Patch
it.groupMatches("none") -> SemverType.None
else -> null
}
private fun getSemver(it: MatchResult) = when {
it.groupMatches("major") -> SemverType.Major
it.groupMatches("minor") -> SemverType.Minor
it.groupMatches("patch") -> SemverType.Patch
it.groupMatches("none") -> SemverType.None
else -> null
}

private fun MatchResult.groupMatches(groupName: String) =
runCatching { [email protected][groupName] }
.getOrNull() != null
private fun MatchResult.groupMatches(groupName: String) = runCatching { [email protected][groupName] }
.getOrNull() != null

fun List<SemverType>.highestPrioritySemver() = maxOrNull()
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,27 @@ object ContributionParser {
ignoreUnknownKeys = true
}

fun parseContributions(jsonString: String) =
json.decodeFromString<Array<ContributionJson>>(jsonString)
.map(ContributionJson::toModel)
fun parseContributions(jsonString: String) = json.decodeFromString<Array<ContributionJson>>(jsonString)
.map(ContributionJson::toModel)

fun parseContribution(jsonString: String) =
json.decodeFromString<ContributionJson?>(jsonString)
?.toModel()
fun parseContribution(jsonString: String) = json.decodeFromString<ContributionJson?>(jsonString)
?.toModel()
}

private fun Contribution.toJsonModel() =
ContributionJson(
lastCommit = lastCommit,
firstCommit = firstCommit,
authors = authors,
dateTime = dateTime,
firstCommitDateTime = firstCommitDateTime,
ease = ease,
storyId = storyId,
semver = semver,
label = label,
tagName = tagName,
tagDateTime = tagDateTime,
commitCount = commitCount,
)
private fun Contribution.toJsonModel() = ContributionJson(
lastCommit = lastCommit,
firstCommit = firstCommit,
authors = authors,
dateTime = dateTime,
firstCommitDateTime = firstCommitDateTime,
ease = ease,
storyId = storyId,
semver = semver,
label = label,
tagName = tagName,
tagDateTime = tagDateTime,
commitCount = commitCount,
)

private fun ContributionJson.toModel() = Contribution(
lastCommit = lastCommit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,22 @@ class ContributionParserTest {
assertEquals(contributions, loaded)
}

private fun stubContribution() =
Contribution(
lastCommit = "${uuid4()}",
firstCommit = "${uuid4()}",
authors = listOf("${uuid4()}"),
dateTime =
randomInstant(),
firstCommitDateTime =
randomInstant(),
ease = Random.nextInt(),
storyId = "${uuid4()}",
semver = "${uuid4()}",
label = "${uuid4()}",
tagDateTime = randomInstant(),
tagName = "${uuid4()}",
commitCount = Random.nextInt(10),
)
private fun stubContribution() = Contribution(
lastCommit = "${uuid4()}",
firstCommit = "${uuid4()}",
authors = listOf("${uuid4()}"),
dateTime =
randomInstant(),
firstCommitDateTime =
randomInstant(),
ease = Random.nextInt(),
storyId = "${uuid4()}",
semver = "${uuid4()}",
label = "${uuid4()}",
tagDateTime = randomInstant(),
tagName = "${uuid4()}",
commitCount = Random.nextInt(10),
)

private fun randomInstant() = Instant.fromEpochMilliseconds(
epochMilliseconds =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class GitAdapter(private val workingDirectory: String, private val env: Map<Stri
),
).trim()

private fun runProcess(args: List<String>, env: Map<String, String> = emptyMap()) =
runProcess(args, workingDirectory, env.plus(this.env))
private fun runProcess(args: List<String>, env: Map<String, String> = emptyMap()) = runProcess(args, workingDirectory, env.plus(this.env))

fun newAnnotatedTag(name: String, ref: String, userName: String?, userEmail: String?) {
runProcess(
Expand Down Expand Up @@ -44,8 +43,7 @@ class GitAdapter(private val workingDirectory: String, private val env: Map<Stri
)
}

private fun inlineConfig(property: String, value: String?) =
if (value != null) listOf("-c", "$property=$value") else emptyList()
private fun inlineConfig(property: String, value: String?) = if (value != null) listOf("-c", "$property=$value") else emptyList()

fun pushTags() {
runProcess(listOf("git", "push", "--tags"))
Expand Down Expand Up @@ -174,8 +172,7 @@ class GitAdapter(private val workingDirectory: String, private val env: Map<Stri
)
}

private fun List<String>.findByPrefix(prefix: String) =
find { it.startsWith(prefix) }?.substring(prefix.length)
private fun List<String>.findByPrefix(prefix: String) = find { it.startsWith(prefix) }?.substring(prefix.length)

fun describe(abbrev: Int): String? = runCatching {
runProcess(listOf("git", "describe", "--abbrev=$abbrev"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ private fun findAppropriateIncrement(
previousTag: String,
implicitPatch: Boolean,
minorRegex: VersionRegex,
): ChangeType? =
gitAdapter.logWithRange("HEAD", "^$previousTag")
.also { if (it.isEmpty()) return null }
.map { it.changeType(minorRegex) ?: if (implicitPatch) ChangeType.Patch else null }
.fold(null, ::highestPriority)
?: if (implicitPatch) ChangeType.Patch else ChangeType.None
): ChangeType? = gitAdapter.logWithRange("HEAD", "^$previousTag")
.also { if (it.isEmpty()) return null }
.map { it.changeType(minorRegex) ?: if (implicitPatch) ChangeType.Patch else null }
.fold(null, ::highestPriority)
?: if (implicitPatch) ChangeType.Patch else ChangeType.None

private fun highestPriority(
left: ChangeType?,
Expand Down Expand Up @@ -127,25 +126,23 @@ enum class SnapshotReason {
fun reasonIsValid(check: StatusCheck): Boolean = check.exists()
}

fun TaggerCore.tagReport() =
adapter.listTags()
.groupBy { tag ->
"${tag.dateTime.toLocalDateTime(TimeZone.currentSystemDefault()).year} Week ${tag.weekNumber()}"
}
.toList()
.sortedBy { (key) -> key }
.joinToString("\n") { (key, value) ->
"$key has ${value.size} tags [${value.joinToString { tag -> tag.name }}]"
}
fun TaggerCore.tagReport() = adapter.listTags()
.groupBy { tag ->
"${tag.dateTime.toLocalDateTime(TimeZone.currentSystemDefault()).year} Week ${tag.weekNumber()}"
}
.toList()
.sortedBy { (key) -> key }
.joinToString("\n") { (key, value) ->
"$key has ${value.size} tags [${value.joinToString { tag -> tag.name }}]"
}

private fun TagRef.weekNumber() =
"${dateTime.toLocalDateTime(TimeZone.currentSystemDefault()).dayOfYear / 7}".let {
if (it.length == 1) {
"0$it"
} else {
it
}
private fun TagRef.weekNumber() = "${dateTime.toLocalDateTime(TimeZone.currentSystemDefault()).dayOfYear / 7}".let {
if (it.length == 1) {
"0$it"
} else {
it
}
}

fun VersionRegex.changeType(message: String): ChangeType? = when {
unified?.containsMatchIn(message) == true -> findMatchType(message, unified)
Expand All @@ -170,6 +167,5 @@ private fun findMatchType(
}
}

private fun MatchGroupCollection?.groupExists(groupName: String): Boolean =
runCatching { this?.get(groupName) != null }
.getOrDefault(false)
private fun MatchGroupCollection?.groupExists(groupName: String): Boolean = runCatching { this?.get(groupName) != null }
.getOrDefault(false)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ object TagErrors {

const val BEING_SNAPSHOT = "being snapshot"
fun alreadyTagged(headTag: String?) = "already tagged $headTag"
fun skipMessageNotOnReleaseBranch(releaseBranch: String?, headBranch: String) =
"not on release branch $releaseBranch - branch was $headBranch"
fun skipMessageNotOnReleaseBranch(releaseBranch: String?, headBranch: String) = "not on release branch $releaseBranch - branch was $headBranch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ open class TaggerExtension(
).version
}

private fun versionRegex() =
VersionRegex(
none = noneRegex.get(),
patch = patchRegex.get(),
minor = minorRegex.get(),
major = majorRegex.get(),
unified = versionRegex.orNull?.also { it.validateVersionRegex() },
)
private fun versionRegex() = VersionRegex(
none = noneRegex.get(),
patch = patchRegex.get(),
minor = minorRegex.get(),
major = majorRegex.get(),
unified = versionRegex.orNull?.also { it.validateVersionRegex() },
)
}

private fun Regex.validateVersionRegex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ interface CalculateVersionTestSpec {
}

fun execute(): TestResult
fun runCalculateVersionSuccessfully(): String =
when (val result = execute()) {
is TestResult.Success -> result.message
is TestResult.Failure -> fail("Expected success but got ${result.reason}")
}
fun runCalculateVersionSuccessfully(): String = when (val result = execute()) {
is TestResult.Success -> result.message
is TestResult.Failure -> fail("Expected success but got ${result.reason}")
}

@Test
fun calculatingVersionWithNoTagsProducesZeroVersion() {
Expand Down