Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Drop snapshot versions
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverAndro committed Jun 13, 2022
1 parent 3680dd6 commit dc33b70
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ object ModrinthAPI : APIInterface() {
?: file.fileName.removeSuffix(".jar"),
version_title = file.displayName,
version_body = "Transferred automatically from https://www.curseforge.com/minecraft/mc-mods/${project.slug}/files/${file.id}",
game_versions = file.gameVersions.filter { MC_SEMVER.matches(it) },
game_versions = getGameVersions(file),
release_channel = when (file.releaseType) {
3 -> "alpha"
2 -> "beta"
Expand Down Expand Up @@ -125,10 +125,30 @@ object ModrinthAPI : APIInterface() {
}
}

private fun getGameVersions(file: CurseforgeFile): List<String> {
val out = mutableSetOf<String>()
file.gameVersions.forEach {
if (MC_SEMVER.matches(it)) {
if (SNAPSHOT_REGEX.containsMatchIn(it)) {
warn(
"Dropping snapshot version $it because curseforge" +
" snapshots are not as precise as modrinth's and cannot" +
"be accurately represented!"
)
} else {
out.add(it)
}
}
}
return out.toList()
}

@Suppress("SpellCheckingInspection")
private val SEMVER =
Regex("(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?")

@Suppress("SpellCheckingInspection")
val MC_SEMVER = Regex("(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:-[sS]napshots?)?")

val SNAPSHOT_REGEX = Regex("-[sS]napshots?")
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "com.github.p03w"
version = "2.1.4"
version = "2.1.5"

repositories {
mavenCentral()
Expand Down

0 comments on commit dc33b70

Please sign in to comment.