matthewprenger / CurseGradle

Gradle plugin to upload Minecraft mods to CurseForge
MIT License
1 stars 1 forks source link

Provide a way to get URL of the upload #34

Open BrainStone opened 3 years ago

BrainStone commented 3 years ago

I think it would be amazing if there was a way to get the URL of the uploaded artifact(s), so it can be processed further down the line.

For example I push a Discord message on release of a new version. So having that URL means I can add that to the message.

ijo42 commented 3 years ago

Check it on https://github.com/ijo42/CurseForge2Discord

jtorleonstudios commented 1 year ago

I think it would be amazing if there was a way to get the URL of the uploaded artifact(s), so it can be processed further down the line.

For example I push a Discord message on release of a new version. So having that URL means I can add that to the message.

You can rebuild the url with the information of the task curseforge (see this response)

example


// Project curseforge identifier
def PROJECT_CURSEFORGE_IDENTIFIER = 12345

// Project curseforge slug
def PROJECT_CURSEFORGE_SLUG = "better-village-fabric"

curseforge {
  apiKey = 'XXXX' 
  project {
    id = PROJECT_CURSEFORGE_IDENTIFIER
   ... YOUR PROCESS...
  }
}

tasks.getByName("curseforge").doLast {
  def fileID = (tasks.getByName("curseforge${PROJECT_CURSEFORGE_IDENTIFIER}").property("mainArtifact"))['fileID']

  // maybe require change for new website ?!
  def fileURL = "https://www.curseforge.com/minecraft/mc-mods/${PROJECT_CURSEFORGE_SLUG}/files/${fileID}"

  // debug (it's for exampe..)
 println fileURL

  //----------------------------------------
  // Is optional, used in my project for my process...
  // create/write file in ./gradle/lastRelease.json 
  def lastRelease = file("gradle/lastRelease.json");
  if (!lastRelease.exists()) lastRelease.createNewFile()
  lastRelease.write("""|{
                       |  "fileId": "${fileID}",
                       |  "slug": "${fileURL}"
                       |}
                       |""".stripMargin())
}

it may be necessary to modify the code to make it work on your project...

The result in ./gradle/lastRelease.json

{
  "fileId": "4436363",
  "slug": "https://www.curseforge.com/minecraft/mc-mods/better-village-fabric/files/4436363"
}

You can then use the information with another task, like sending it to your discord with a webhook message...