Skip to content

Commit

Permalink
chore: update how the body limit is applied
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Dec 11, 2024
1 parent 8d45e52 commit 791e11e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions discord.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ task discordupload {
"${getReleaseChangelog()}\n"

if (content.length() > maxLength) {
def afterMessage = "[See more on GitHub](https://github.com/sekwah41/Advanced-Portals/releases)"
def afterMessage = "[See more on GitHub](<https://github.com/sekwah41/Advanced-Portals/releases>)"

def truncatedContent = content.take(maxLength - afterMessage.length() - 1)
def truncatedContent = content.replaceAll(/(http[s]?:\/\/[^\s)]+)/, '<$1>').take(maxLength - afterMessage.length() - 1)
def lastFullLine = truncatedContent.lastIndexOf("\n")
content = "${truncatedContent.take(lastFullLine)}\n" +
"${afterMessage}"
content = "${truncatedContent.take(lastFullLine)}\n"
content += afterMessage

}

content = content.replaceAll(/(http[s]?:\/\/[^\s)]+)/, '<$1>')

builder.addTextBody("content", content, ContentType.create("text/plain", "UTF-8"))
}

Expand All @@ -63,7 +61,15 @@ task discordupload {
response.getEntity()

if(response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Failed to post build to discord")
println("Failed to post build to Discord.")
println("Status Code: " + response.getStatusLine().getStatusCode())
println("Reason Phrase: " + response.getStatusLine().getReasonPhrase())

String responseContent = response.getEntity() != null ?
org.apache.http.util.EntityUtils.toString(response.getEntity()) : "No content"
println("Response Content: " + responseContent)

throw new RuntimeException("Failed to post build to Discord")
}

println("Posted build")
Expand Down

0 comments on commit 791e11e

Please sign in to comment.