docs: properly handle semantic versions (#156) [skip ci]
This commit is contained in:
parent
c06e9b09d7
commit
e6029d6716
|
@ -1,5 +1,7 @@
|
|||
package app.revanced.meta.readme
|
||||
|
||||
import SemanticVersion
|
||||
import SemanticVersionComparator
|
||||
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
||||
import app.revanced.patcher.extensions.PatchExtensions.description
|
||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||
|
@ -21,7 +23,8 @@ class Generator {
|
|||
for (patch in bundle) {
|
||||
val patchName = patch.patchName
|
||||
val compatiblePackage = patch.compatiblePackages?.first()
|
||||
val latestVersion = compatiblePackage?.versions?.maxByOrNull { it.replace(".", "").toInt() } ?: "all"
|
||||
val latestVersion =
|
||||
compatiblePackage?.versions?.map { SemanticVersion.fromString(it) }?.maxWithOrNull(SemanticVersionComparator) ?: "all"
|
||||
|
||||
patches.appendLine("| `$patchName` | ${patch.description} | `${compatiblePackage?.name}` | $latestVersion |")
|
||||
}
|
||||
|
|
22
src/main/kotlin/app/revanced/meta/readme/Semver.kt
Normal file
22
src/main/kotlin/app/revanced/meta/readme/Semver.kt
Normal file
|
@ -0,0 +1,22 @@
|
|||
data class SemanticVersion(val major: Int, val minor: Int, val patch: Int) {
|
||||
companion object {
|
||||
fun fromString(version: String): SemanticVersion {
|
||||
var parts = version.split(".")
|
||||
|
||||
if (parts.count() != 3) throw IllegalArgumentException("Invalid semantic version")
|
||||
|
||||
val versionNumbers = parts.map { it.toInt() }
|
||||
return SemanticVersion(versionNumbers[0], versionNumbers[1], versionNumbers[2])
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = "$major.$minor.$patch"
|
||||
}
|
||||
|
||||
object SemanticVersionComparator : Comparator<SemanticVersion> {
|
||||
override fun compare(a: SemanticVersion, b: SemanticVersion): Int = when {
|
||||
a.major != b.major -> a.major - b.major
|
||||
a.minor != b.minor -> a.minor - b.minor
|
||||
else -> a.patch - b.patch
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue