1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

githubPublishRelease - ensure proper JSON encoding (#807)

So far some special characters have not been properly encoded when creating a release.
This is addressed by using a new JsonUtils method now.
This commit is contained in:
Oliver Nocon 2019-07-26 14:03:20 +02:00 committed by GitHub
parent e8821c2b90
commit 153dbf2a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View File

@ -7,6 +7,11 @@ String groovyObjectToPrettyJsonString(object) {
return groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(object))
}
@NonCPS
String groovyObjectToJsonString(object) {
return groovy.json.JsonOutput.toJson(object)
}
@NonCPS
def jsonStringToGroovyObject(text) {
return new groovy.json.JsonSlurperClassic().parseText(text)

View File

@ -213,4 +213,5 @@ class GithubPublishReleaseTest extends BasePiperTest {
assertThat(stepRule.step.isExcluded(item, ['won\'t fix']), is(false))
assertJobStatusSuccess()
}
}

View File

@ -1,3 +1,5 @@
import com.sap.piper.JsonUtils
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.GenerateDocumentation
@ -146,9 +148,15 @@ String addDeltaToLastRelease(config, latestTag){
}
void postNewRelease(config, TOKEN, releaseBody){
releaseBody = releaseBody.replace('"', '\\"')
//write release information
def data = "{\"tag_name\": \"${config.version}\",\"target_commitish\": \"master\",\"name\": \"${config.version}\",\"body\": \"${releaseBody}\",\"draft\": false,\"prerelease\": false}"
Map messageBody = [
tag_name: "${config.version}",
target_commitish: 'master',
name: "${config.version}",
body: releaseBody,
draft: false,
prerelease: false
]
def data = new JsonUtils().groovyObjectToJsonString(messageBody)
try {
httpRequest httpMode: 'POST', requestBody: data, url: "${config.githubApiUrl}/repos/${config.githubOrg}/${config.githubRepo}/releases?access_token=${TOKEN}"
} catch (e) {