mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-12-23 09:28:06 +01:00
71 lines
2.2 KiB
Groovy
71 lines
2.2 KiB
Groovy
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'
|
|
apply from: 'changelog-util.gradle'
|
|
|
|
task discordupload {
|
|
dependsOn(jar)
|
|
|
|
doLast {
|
|
|
|
String discordWebhook = isRelease ? System.getenv("DISCORD_RELEASE_WEBHOOK") : System.getenv("DISCORD_WEBHOOK")
|
|
|
|
if(discordWebhook != null) {
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault()
|
|
HttpPost uploadFile = new HttpPost(discordWebhook)
|
|
|
|
MultipartEntityBuilder builder = MultipartEntityBuilder.create()
|
|
if(!isRelease) {
|
|
builder.addTextBody("content", "New snapshot or testing build")
|
|
} else {
|
|
def maxLength = 2000
|
|
|
|
def content = "New release build\n" +
|
|
"${getReleaseChangelog()}\n"
|
|
|
|
if (content.length() > maxLength) {
|
|
def afterMessage = "[See more on GitHub]"
|
|
content = "${content.take(maxLength - afterMessage.length() - 1)}\n" +
|
|
"${afterMessage}"
|
|
|
|
}
|
|
|
|
builder.addTextBody("content", content, ContentType.create("text/plain", "UTF-8"))
|
|
}
|
|
|
|
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()
|
|
|
|
if(response.getStatusLine().getStatusCode() != 200) {
|
|
throw new RuntimeException("Failed to post build to discord")
|
|
}
|
|
|
|
println("Posted build")
|
|
|
|
} else {
|
|
println("Discord webhook unspecified")
|
|
}
|
|
}
|
|
}
|