factorio mod deploy tweaks (better confirmation and link to the page)

This commit is contained in:
Adam 2022-06-19 11:29:07 +02:00
parent 0398e2026d
commit d2768c3c9e
3 changed files with 37 additions and 14 deletions

View file

@ -36,6 +36,7 @@ class FactorioModPortalPublishClient(
private val modVersion: String,
private val portalApiKey: String,
private val portalUploadEndpoint: String,
private val modPortalBaseURl: String,
) {
private fun client() = HttpClient(CIO) {
@ -61,11 +62,18 @@ class FactorioModPortalPublishClient(
client().useToRun {
val initUploadResponse = initUpload()
val confirmation = userInputHandler
.askQuestion("Are you sure you want to publish $modName:$modVersion?", "no")
.toBooleanLenient() ?: false
val enteredVersion = userInputHandler
.askQuestion(
"""
|Are you sure you want to publish $modName:$modVersion?
|Enter the version number to confirm:
""".trimMargin(),
"",
)
if (confirmation) {
val confirmed = enteredVersion.trim() == modVersion.trim()
if (confirmed) {
upload(initUploadResponse)
} else {
println("aborting upload")
@ -120,6 +128,7 @@ class FactorioModPortalPublishClient(
require(response.status.isSuccess() && submitUploadResponse is SubmitUploadResponse.Success) {
"upload request failed"
}
println("Mod uploaded successfully! ${modPortalBaseURl.removeSuffix("/")}/$modName")
}
companion object {

View file

@ -44,6 +44,15 @@ abstract class FactorioModPublishTask @Inject constructor(
val portalApiUrl: Property<String> = objects.property<String>()
.convention("https://mods.factorio.com/api/v2/")
/**
* Base URL for linking to a mod page in the portal
*
* Example `https://mods.factorio.com/mod/my-mod-name`
*/
@get:Input
val modPortalBaseURl: Property<String> = objects.property<String>()
.convention("https://mods.factorio.com/mod/")
@get:Input
val portalUploadEndpoint: Property<String> = objects.property<String>()
.convention("mods/releases/init_upload")
@ -65,12 +74,13 @@ abstract class FactorioModPublishTask @Inject constructor(
.buildString()
val client = FactorioModPortalPublishClient(
userInputHandler,
distributionZip.get().asFile,
modName.get(),
modVersion.get(),
portalApiKey.get(),
portalUploadEndpoint,
userInputHandler = userInputHandler,
distributionZip = distributionZip.get().asFile,
modName = modName.get(),
modVersion = modVersion.get(),
portalApiKey = portalApiKey.get(),
portalUploadEndpoint = portalUploadEndpoint,
modPortalBaseURl = modPortalBaseURl.get(),
)
client.uploadMod()