diff --git a/src/main/kotlin/com/dsoftware/ghmanager/api/GetJobLogRequest.kt b/src/main/kotlin/com/dsoftware/ghmanager/api/GetJobLogRequest.kt index bc8de9a5..15f39c7c 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/api/GetJobLogRequest.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/api/GetJobLogRequest.kt @@ -9,6 +9,7 @@ import java.io.BufferedReader import java.io.IOException import java.io.InputStream import java.io.InputStreamReader +import java.text.ParseException import java.text.SimpleDateFormat import java.util.Date import java.util.TimeZone @@ -44,7 +45,7 @@ class GetJobLogRequest(private val job: Job) : GithubApiRequest.Get(job. var currStep = 1 try { val reader = BufferedReader(InputStreamReader(inputStream)) - val lines = reader.readLines() + val lines = reader.lines() for (line in lines) { ++lineNum if (line.length < 29) { @@ -52,9 +53,12 @@ class GetJobLogRequest(private val job: Job) : GithubApiRequest.Get(job. continue } val datetimeStr = line.substring(0, 23) - val time = formatter.parse(datetimeStr) - currStep = findStep(currStep, time) - + try { + val time = formatter.parse(datetimeStr) + currStep = findStep(currStep, time) + } catch (e: ParseException) { + LOG.warn("Failed to parse date from log line $lineNum: $line, $e") + } contentBuilders.getOrPut(currStep) { StringBuilder(400_000) }.append(line + "\n") } } catch (e: IOException) { diff --git a/src/main/kotlin/com/dsoftware/ghmanager/api/model/RunModel.kt b/src/main/kotlin/com/dsoftware/ghmanager/api/model/RunModel.kt index d6ba9d95..f5d25496 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/api/model/RunModel.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/api/model/RunModel.kt @@ -1,23 +1,9 @@ package com.dsoftware.ghmanager.api.model import com.fasterxml.jackson.annotation.JsonFormat -import kotlinx.serialization.Serializable import java.util.Date -data class WorkflowTypes( - val totalCount: Int, - val workflows: List = emptyList() -) - -@Serializable -data class WorkflowType( - val id: Long, - val name: String, - val path: String, - val state: String, -) - data class PullRequest( val id: Int, val number: Int, diff --git a/src/main/kotlin/com/dsoftware/ghmanager/api/model/WorkflowTypes.kt b/src/main/kotlin/com/dsoftware/ghmanager/api/model/WorkflowTypes.kt new file mode 100644 index 00000000..569ba3f7 --- /dev/null +++ b/src/main/kotlin/com/dsoftware/ghmanager/api/model/WorkflowTypes.kt @@ -0,0 +1,16 @@ +package com.dsoftware.ghmanager.api.model + +import kotlinx.serialization.Serializable + +data class WorkflowTypes( + val totalCount: Int, + val workflows: List = emptyList() +) + +@Serializable +data class WorkflowType( + val id: Long, + val name: String, + val path: String, + val state: String, +) \ No newline at end of file diff --git a/src/test/kotlin/com/dsoftware/ghmanager/TestGetJobLogRequest.kt b/src/test/kotlin/com/dsoftware/ghmanager/TestGetJobLogRequest.kt index 81f7962c..61464742 100644 --- a/src/test/kotlin/com/dsoftware/ghmanager/TestGetJobLogRequest.kt +++ b/src/test/kotlin/com/dsoftware/ghmanager/TestGetJobLogRequest.kt @@ -53,4 +53,18 @@ class TestGetJobLogRequest : TestCase() { assertTrue(log.contains("[31m---- Step 3: step 3 (failed) ----")) } + fun testBadLogStructure() { + // arrange + val wfJobsJson = TestGetJobLogRequest::class.java.getResource("/wf-run-jobs.json")!!.readText() + val wfJobs: WorkflowRunJobs = mapper.readValue(wfJobsJson) + val job = wfJobs.jobs.first() + val line="2024-02-11T18:09:51.DDDDDDDZ LTS\n" + //act + val log = GetJobLogRequest(job).extractJobLogFromStream(line.byteInputStream()) + + //assert + assertTrue(log.contains(line)) + + } + } \ No newline at end of file