2022-04-24 14:44:14 +02:00
|
|
|
import org.apache.http.HttpEntity
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse
|
|
|
|
import org.apache.http.client.methods.HttpPost
|
|
|
|
import org.apache.http.entity.ContentType
|
|
|
|
import org.apache.http.entity.mime.MultipartEntityBuilder
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient
|
|
|
|
import org.apache.http.impl.client.HttpClients
|
|
|
|
|
|
|
|
buildscript {
|
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
|
|
|
}
|
|
|
|
dependencies {
|
|
|
|
classpath "org.apache.httpcomponents:httpmime:4.5.13"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
apply from: 'env-variables.gradle'
|
|
|
|
|
2024-11-19 01:27:54 +01:00
|
|
|
def getReleaseChangelog() {
|
|
|
|
def changelogFile = file('CHANGELOG.md')
|
|
|
|
def changelog = "## [${changelogFile.text.split('\n## \\[')[1]}\n\n"// ${project.github}/blob/${branch}/CHANGELOG.md
|
|
|
|
return changelog;
|
|
|
|
}
|
|
|
|
|
2022-04-24 14:44:14 +02:00
|
|
|
task discordupload {
|
|
|
|
dependsOn(jar)
|
2024-11-19 01:27:54 +01:00
|
|
|
|
2022-04-24 14:44:14 +02:00
|
|
|
doLast {
|
2024-11-19 01:27:54 +01:00
|
|
|
|
2022-04-24 14:44:14 +02:00
|
|
|
String discordWebhook = System.getenv("DISCORD_WEBHOOK")
|
|
|
|
|
|
|
|
if(discordWebhook != null) {
|
|
|
|
println("Logging Into Discord")
|
|
|
|
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault()
|
|
|
|
HttpPost uploadFile = new HttpPost(discordWebhook)
|
|
|
|
|
|
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create()
|
2024-11-19 01:27:54 +01:00
|
|
|
if(!isRelease) {
|
|
|
|
builder.addTextBody("content", "New snapshot or testing build")
|
|
|
|
} else {
|
|
|
|
def maxLength = 2000
|
|
|
|
|
|
|
|
def content = "New release build\n" +
|
|
|
|
"```markdown\n" +
|
|
|
|
"${getReleaseChangelog()}\n" +
|
|
|
|
"```"
|
|
|
|
|
|
|
|
if (content.length() > maxLength) {
|
|
|
|
def trimmedChangelog = getReleaseChangelog().take(maxLength - 15) // Reserve space for ending message
|
|
|
|
content = "New release build\n" +
|
|
|
|
"```markdown\n" +
|
|
|
|
"${trimmedChangelog}\n" +
|
|
|
|
"``` [Truncated]"
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.addTextBody("content", content)
|
|
|
|
}
|
2022-04-24 14:44:14 +02:00
|
|
|
|
|
|
|
builder.addBinaryBody("file", file(jar.archiveFile).newInputStream(), ContentType.APPLICATION_OCTET_STREAM, jar.archiveName)
|
|
|
|
|
|
|
|
HttpEntity multipart = builder.build()
|
|
|
|
|
|
|
|
uploadFile.setEntity(multipart)
|
|
|
|
CloseableHttpResponse response = httpClient.execute(uploadFile)
|
|
|
|
response.getEntity()
|
|
|
|
|
|
|
|
println("Posted build")
|
|
|
|
|
|
|
|
} else {
|
2024-11-19 01:27:54 +01:00
|
|
|
println("Discord webhook unspecified")
|
2022-04-24 14:44:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|