diff --git a/util/jenkins/src/main/kotlin/voodoo.util/jenkins/Jenkins.kt b/util/jenkins/src/main/kotlin/voodoo.util/jenkins/Jenkins.kt index e1df919e..94357c55 100644 --- a/util/jenkins/src/main/kotlin/voodoo.util/jenkins/Jenkins.kt +++ b/util/jenkins/src/main/kotlin/voodoo.util/jenkins/Jenkins.kt @@ -10,12 +10,19 @@ import io.ktor.http.isSuccess import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json import mu.KLogging +import mu.KotlinLogging import voodoo.util.useClient import java.io.IOException import voodoo.util.json -object Jenkins : KLogging() + +private val logger = KotlinLogging.logger{} + +private val jenkinsJson = Json(json) { + ignoreUnknownKeys = true +} class JenkinsServer( val serverUrl: String @@ -33,16 +40,16 @@ class JenkinsServer( } } catch (e: IOException) { - Jenkins.logger.error("requestURL: $requestURL") + logger.error("requestURL: $requestURL") // Jenkins.logger.error("response: $response") - Jenkins.logger.error(e) { "unable to get job from $requestURL" } + logger.error(e) { "unable to get job from $requestURL" } return@withContext null } if (!response.status.isSuccess()) { - Jenkins.logger.error { "$requestURL returned ${response.status}" } + logger.error { "$requestURL returned ${response.status}" } return@withContext null } - return@withContext json.decodeFromString(Job.serializer(), response.readText()) + return@withContext jenkinsJson.decodeFromString(Job.serializer(), response.readText()) } } @@ -62,17 +69,17 @@ data class Build( } } catch(e: IOException) { - Jenkins.logger.error("buildUrl: $buildUrl") + logger.error("buildUrl: $buildUrl") // Jenkins.logger.error("response: $response") - Jenkins.logger.error(e) { "unable to get build from $buildUrl" } + logger.error(e) { "unable to get build from $buildUrl" } return@withContext null } if(!response.status.isSuccess()) { - Jenkins.logger.error { "$buildUrl returned ${response.status}" } + logger.error { "$buildUrl returned ${response.status}" } return@withContext null } - return@withContext json.decodeFromString(BuildWithDetails.serializer(), response.readText()) + return@withContext jenkinsJson.decodeFromString(BuildWithDetails.serializer(), response.readText()) } } diff --git a/util/src/main/kotlin/voodoo/util/JsonExtension.kt b/util/src/main/kotlin/voodoo/util/JsonExtension.kt index fd6f6e01..509e6de0 100644 --- a/util/src/main/kotlin/voodoo/util/JsonExtension.kt +++ b/util/src/main/kotlin/voodoo/util/JsonExtension.kt @@ -11,7 +11,6 @@ import kotlinx.serialization.json.Json val json = Json { prettyPrint = true encodeDefaults = false - this.classDiscriminator } inline fun T.toJson(serializer: SerializationStrategy): String = json.encodeToString(serializer, this)