Skip to content

Commit

Permalink
changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Feb 14, 2024
1 parent 3627e3e commit 2b39a7b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
12 changes: 8 additions & 4 deletions src/main/kotlin/com/dsoftware/ghmanager/api/GetJobLogRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,17 +45,20 @@ class GetJobLogRequest(private val job: Job) : GithubApiRequest.Get<String>(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) {
contentBuilders.getOrDefault(currStep, StringBuilder()).append(line + "\n")
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) {
Expand Down
14 changes: 0 additions & 14 deletions src/main/kotlin/com/dsoftware/ghmanager/api/model/RunModel.kt
Original file line number Diff line number Diff line change
@@ -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<WorkflowType> = 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,
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/com/dsoftware/ghmanager/api/model/WorkflowTypes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.dsoftware.ghmanager.api.model

import kotlinx.serialization.Serializable

data class WorkflowTypes(
val totalCount: Int,
val workflows: List<WorkflowType> = emptyList()
)

@Serializable
data class WorkflowType(
val id: Long,
val name: String,
val path: String,
val state: String,
)
14 changes: 14 additions & 0 deletions src/test/kotlin/com/dsoftware/ghmanager/TestGetJobLogRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))

}

}

0 comments on commit 2b39a7b

Please sign in to comment.