Skip to content

Commit

Permalink
fix jenkins json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Jan 20, 2021
1 parent e748663 commit 799de1f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
25 changes: 16 additions & 9 deletions util/jenkins/src/main/kotlin/voodoo.util/jenkins/Jenkins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
}
}

Expand All @@ -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())
}
}

Expand Down
1 change: 0 additions & 1 deletion util/src/main/kotlin/voodoo/util/JsonExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import kotlinx.serialization.json.Json
val json = Json {
prettyPrint = true
encodeDefaults = false
this.classDiscriminator
}

inline fun <reified T : Any> T.toJson(serializer: SerializationStrategy<T>): String = json.encodeToString(serializer, this)

0 comments on commit 799de1f

Please sign in to comment.