Skip to content

Commit

Permalink
Add configuration for CurseForge changelog type (#59)
Browse files Browse the repository at this point in the history
* Close #58 Add configuration for CurseForge changelog type

* set default value for changelogType

* Make changelogType a string

* update tests and docs
  • Loading branch information
mezz authored Sep 7, 2024
1 parent 4f77ba3 commit 506f4f3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/pages/platforms/curseforge.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ publishMods {
optional("project-slug")
incompatible("project-slug")
embeds("project-slug")
// Set a changelog using text, markdown, or html (defaults to markdown)
changelog = "# Markdown changelog content"
changelogType = "markdown"
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ interface CurseforgeOptions : PlatformOptions, PlatformOptionsInternal<Curseforg
@get:Input
val apiEndpoint: Property<String>

@get:Input
val changelogType: Property<String>

fun from(other: CurseforgeOptions) {
super.from(other)
fromDependencies(other)
Expand All @@ -63,6 +66,7 @@ interface CurseforgeOptions : PlatformOptions, PlatformOptionsInternal<Curseforg
serverRequired.set(other.serverRequired)
javaVersions.set(other.javaVersions)
apiEndpoint.set(other.apiEndpoint)
changelogType.set(other.changelogType)
}

fun from(other: Provider<CurseforgeOptions>) {
Expand Down Expand Up @@ -90,6 +94,7 @@ interface CurseforgeOptions : PlatformOptions, PlatformOptionsInternal<Curseforg

override fun setInternalDefaults() {
apiEndpoint.convention("https://minecraft.curseforge.com")
changelogType.convention("markdown")
}

override val platformDependencyKClass: KClass<CurseforgeDependency>
Expand Down Expand Up @@ -219,7 +224,7 @@ abstract class Curseforge @Inject constructor(name: String) : Platform(name), Cu

val metadata = CurseforgeApi.UploadFileMetadata(
changelog = changelog.get(),
changelogType = "markdown",
changelogType = CurseforgeApi.ChangelogType.of(changelogType.get()),
displayName = displayName.get(),
gameVersions = gameVersions,
releaseType = CurseforgeApi.ReleaseType.valueOf(type.get()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,35 @@ class CurseforgeApi(private val accessToken: String, private val baseUrl: String
}
}

@Serializable
enum class ChangelogType {
@SerialName("text")
TEXT,

@SerialName("html")
HTML,

@SerialName("markdown")
MARKDOWN,
;

companion object {
@JvmStatic
fun of(value: String): ChangelogType {
val upper = value.uppercase()
try {
return ChangelogType.valueOf(upper)
} catch (e: java.lang.IllegalArgumentException) {
throw java.lang.IllegalArgumentException("Invalid changelog type: $upper. Must be one of: TEXT, HTML, MARKDOWN")
}
}
}
}

@Serializable
data class UploadFileMetadata(
val changelog: String, // Can be HTML or markdown if changelogType is set.
val changelogType: String? = null, // Optional: defaults to text
val changelogType: ChangelogType? = null, // Optional: defaults to text
val displayName: String? = null, // Optional: A friendly display name used on the site if provided.
val parentFileID: Int? = null, // Optional: The parent file of this file.
val gameVersions: List<Int>?, // A list of supported game versions, see the Game Versions API for details. Not supported if parentFileID is provided.
Expand Down
13 changes: 11 additions & 2 deletions src/test/kotlin/me/modmuss50/mpp/test/curseforge/CurseforgeTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.modmuss50.mpp.test.curseforge

import me.modmuss50.mpp.platforms.curseforge.CurseforgeApi
import me.modmuss50.mpp.test.IntegrationTest
import me.modmuss50.mpp.test.MockWebServer
import org.gradle.testkit.runner.TaskOutcome
Expand All @@ -17,7 +18,7 @@ class CurseforgeTest : IntegrationTest {
"""
publishMods {
file = tasks.jar.flatMap { it.archiveFile }
changelog = "Hello!"
changelog = "<p>Hello!</p>"
version = "1.0.0"
type = BETA
modLoaders.add("fabric")
Expand All @@ -30,6 +31,7 @@ class CurseforgeTest : IntegrationTest {
javaVersions.add(JavaVersion.VERSION_17)
clientRequired = true
serverRequired = true
changelogType = "html"
requires {
slug = "fabric-api"
Expand All @@ -48,7 +50,8 @@ class CurseforgeTest : IntegrationTest {
val metadata = server.api.lastMetadata!!

assertEquals(TaskOutcome.SUCCESS, result.task(":publishCurseforge")!!.outcome)
assertEquals("Hello!", metadata.changelog)
assertEquals("<p>Hello!</p>", metadata.changelog)
assertEquals(CurseforgeApi.ChangelogType.HTML, metadata.changelogType)
assertEquals("Test Upload", metadata.displayName)
assertContains(metadata.gameVersions!!, 9990) // 1.20.1
assertContains(metadata.gameVersions!!, 7499) // Fabric
Expand Down Expand Up @@ -87,6 +90,7 @@ class CurseforgeTest : IntegrationTest {
start = "1.19.4"
end = "1.20.1"
}
changelogType = "text"
}
curseforge("curseforgeFabric") {
Expand Down Expand Up @@ -120,6 +124,7 @@ class CurseforgeTest : IntegrationTest {
assertContains(metadata.gameVersions!!, 9776) // 1.19.4
assertContains(metadata.gameVersions!!, 9971) // 1.20
assertContains(metadata.gameVersions!!, 9990) // 1.20.1
assertEquals(CurseforgeApi.ChangelogType.TEXT, metadata.changelogType)
}

// Also test in groovy to ensure that the closures are working as expected
Expand Down Expand Up @@ -147,6 +152,7 @@ class CurseforgeTest : IntegrationTest {
accessToken = "123"
minecraftVersions.add("1.20.1")
apiEndpoint = "${server.endpoint}"
changelogType = "markdown"
}
curseforge("curseforgeFabric") {
Expand All @@ -171,10 +177,13 @@ class CurseforgeTest : IntegrationTest {
.run("publishMods")
server.close()

val metadata = server.api.lastMetadata!!

assertEquals(TaskOutcome.SUCCESS, result.task(":publishCurseforgeFabric")!!.outcome)
assertEquals(TaskOutcome.SUCCESS, result.task(":publishCurseforgeForge")!!.outcome)
assertContains(server.api.files, "mpp-example-forge.jar")
assertContains(server.api.files, "mpp-example-fabric.jar")
assertEquals(CurseforgeApi.ChangelogType.MARKDOWN, metadata.changelogType)
}

@Test
Expand Down

0 comments on commit 506f4f3

Please sign in to comment.