Rename VersionPart to ReleaseType

This commit is contained in:
William Brawner 2023-09-29 07:44:24 -06:00
parent c04e2ded8e
commit 80e323b326
Signed by: wbrawner
GPG key ID: 8FF12381C6C90D35

View file

@ -2,7 +2,6 @@ package com.wbrawner.releasehelper
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Exec import org.gradle.api.tasks.Exec
import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.provideDelegate
@ -48,7 +47,7 @@ class ReleaseHelperPlugin : Plugin<Project> {
dependsOn("changelog", "getLatestTag") dependsOn("changelog", "getLatestTag")
doLast { doLast {
val latestTag: String by target.project.extra val latestTag: String by target.project.extra
val newVersion = latestTag.incrementVersion(VersionPart.MAJOR) val newVersion = latestTag.incrementVersion(ReleaseType.MAJOR)
target.updateVersionName(latestTag, newVersion) target.updateVersionName(latestTag, newVersion)
target.exec { target.exec {
commandLine = "git tag $newVersion".split(" ") commandLine = "git tag $newVersion".split(" ")
@ -60,7 +59,7 @@ class ReleaseHelperPlugin : Plugin<Project> {
dependsOn("changelog", "getLatestTag") dependsOn("changelog", "getLatestTag")
doLast { doLast {
val latestTag: String by target.project.extra val latestTag: String by target.project.extra
val newVersion = latestTag.incrementVersion(VersionPart.MAJOR) val newVersion = latestTag.incrementVersion(ReleaseType.MAJOR)
target.updateVersionName(latestTag, newVersion) target.updateVersionName(latestTag, newVersion)
target.exec { target.exec {
commandLine = "git tag $newVersion".split(" ") commandLine = "git tag $newVersion".split(" ")
@ -72,7 +71,7 @@ class ReleaseHelperPlugin : Plugin<Project> {
dependsOn("changelog", "getLatestTag") dependsOn("changelog", "getLatestTag")
doLast { doLast {
val latestTag: String by target.project.extra val latestTag: String by target.project.extra
val newVersion = latestTag.incrementVersion(VersionPart.MAJOR) val newVersion = latestTag.incrementVersion(ReleaseType.MAJOR)
target.updateVersionName(latestTag, newVersion) target.updateVersionName(latestTag, newVersion)
target.exec { target.exec {
commandLine = "git tag $newVersion".split(" ") commandLine = "git tag $newVersion".split(" ")
@ -82,18 +81,18 @@ class ReleaseHelperPlugin : Plugin<Project> {
} }
} }
private enum class VersionPart { private enum class ReleaseType {
MAJOR, MAJOR,
MINOR, MINOR,
PATCH PATCH
} }
private fun String.incrementVersion(part: VersionPart) = split(".") private fun String.incrementVersion(releaseType: ReleaseType) = split(".")
.mapIndexed { index, numberString -> .mapIndexed { index, numberString ->
val number = numberString.toInt() val number = numberString.toInt()
return@mapIndexed if (index == part.ordinal) { return@mapIndexed if (index == releaseType.ordinal) {
number + 1 number + 1
} else if (index > part.ordinal) { } else if (index > releaseType.ordinal) {
0 0
} else { } else {
number number