generated from JetBrains/intellij-platform-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,891 additions
and
986 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 57 additions & 21 deletions
78
src/main/kotlin/com/dsoftware/ghmanager/api/GetRunLogRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,80 @@ | ||
package com.dsoftware.ghmanager.api | ||
|
||
import com.dsoftware.ghmanager.api.model.Job | ||
import com.intellij.openapi.diagnostic.logger | ||
import com.jetbrains.rd.util.first | ||
import org.jetbrains.plugins.github.api.GithubApiRequest | ||
import org.jetbrains.plugins.github.api.GithubApiResponse | ||
import java.io.BufferedReader | ||
import java.io.IOException | ||
import java.io.InputStream | ||
import java.io.InputStreamReader | ||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import java.util.TimeZone | ||
|
||
|
||
class GetJobLogRequest(url: String) : GithubApiRequest.Get<JobLog>(url) { | ||
class GetJobLogRequest(private val job: Job) : GithubApiRequest.Get<JobLog>(job.url + "/logs") { | ||
override fun extractResult(response: GithubApiResponse): JobLog { | ||
LOG.debug("extracting result for $url") | ||
return response.handleBody { | ||
extractJobLogFromStream(it) | ||
} | ||
} | ||
|
||
companion object { | ||
private val LOG = logger<GetJobLogRequest>() | ||
fun extractJobLogFromStream(inputStream: InputStream): JobLog { | ||
val content = HashMap<Int, String>() | ||
var stepNumber = 1 | ||
try { | ||
val reader = BufferedReader(InputStreamReader(inputStream)) | ||
val stepLog = StringBuilder() | ||
for (line in reader.lines()) { | ||
if (line.contains("##[group]Run ")) { | ||
content[stepNumber] = stepLog.toString() | ||
stepLog.clear() | ||
stepNumber++ | ||
} else { | ||
stepLog.append(line + "\n") | ||
} | ||
fun extractJobLogFromStream(inputStream: InputStream): JobLog { | ||
val dateTimePattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSSX" | ||
val formatter = SimpleDateFormat(dateTimePattern) | ||
val stepsPeriodMap: Map<Int, Pair<Date?, Date?>> = job.steps?.associate { step -> | ||
val start = if(step.startedAt != null) formatter.parse(step.startedAt) else null | ||
val completed = if(step.completedAt != null) formatter.parse(step.completedAt) else null | ||
step.number to (start to completed) | ||
} ?: emptyMap() | ||
val contentBuilders = HashMap<Int, StringBuilder>() | ||
|
||
formatter.timeZone = TimeZone.getTimeZone("UTC") | ||
fun findStep(datetimeStr: String): Int { | ||
val time = formatter.parse(datetimeStr) | ||
var lo = 0 | ||
var hi = job.steps!!.size - 1 | ||
while (lo <= hi) { | ||
val mid = (lo + hi) / 2 | ||
val midVal = stepsPeriodMap[mid] | ||
if (midVal?.second != null && midVal.second!!.before(time)) { | ||
lo = mid + 1 | ||
} else if (midVal?.first != null && midVal.first!!.after(time)) { | ||
hi = mid - 1 | ||
} else { | ||
return mid | ||
} | ||
} | ||
return -1 | ||
} | ||
try { | ||
val reader = BufferedReader(InputStreamReader(inputStream)) | ||
val lines = reader.lines() | ||
|
||
var lineNum = 0 | ||
var currStep = 0 | ||
for (line in lines) { | ||
++lineNum | ||
if (line.length < 29) { | ||
contentBuilders.getOrDefault(currStep, StringBuilder()).append(line + "\n") | ||
continue | ||
} | ||
} catch (e: IOException) { | ||
LOG.warn(e.message) | ||
throw e | ||
val dateStr = line.substring(0, 28) | ||
currStep = findStep(dateStr) | ||
contentBuilders.getOrDefault(currStep, StringBuilder()).append(line + "\n") | ||
} | ||
return content | ||
} catch (e: IOException) { | ||
LOG.warn(e.message) | ||
throw e | ||
} | ||
return contentBuilders.map { (k, v) -> k to v.toString() }.toMap() | ||
} | ||
|
||
companion object { | ||
private val LOG = logger<GetJobLogRequest>() | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/kotlin/com/dsoftware/ghmanager/TestGetJobLogRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.dsoftware.ghmanager | ||
|
||
import com.dsoftware.ghmanager.api.model.Job | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import com.intellij.testFramework.fixtures.BasePlatformTestCase | ||
|
||
class TestGetJobLogRequest : BasePlatformTestCase() { | ||
private val mapper = ObjectMapper().registerKotlinModule() | ||
|
||
fun testGetJobLogRequest() { | ||
val logContent = TestGetJobLogRequest::class.java.getResource("wf-run-single-job.log")?.readText() | ||
val jobJson = TestGetJobLogRequest::class.java.getResource("wf-run-single-job.json")?.readText() | ||
val obj: List<Job> = mapper.readValue(json) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{ | ||
"id": 21454796844, | ||
"run_id": 7863783013, | ||
"workflow_name": "Push on master", | ||
"head_branch": "master", | ||
"run_url": "https://api.github.com/repos/cunla/fakeredis-py/actions/runs/7863783013", | ||
"run_attempt": 1, | ||
"node_id": "CR_kwDOHLrRQs8AAAAE_s44LA", | ||
"head_sha": "a0576c489ba7cad8cad4ba7e14a7fe30ef9959a1", | ||
"url": "https://api.github.com/repos/cunla/fakeredis-py/actions/jobs/21454796844", | ||
"html_url": "https://github.com/cunla/fakeredis-py/actions/runs/7863783013/job/21454796844", | ||
"status": "completed", | ||
"conclusion": "success", | ||
"created_at": "2024-02-11T18:09:46Z", | ||
"started_at": "2024-02-11T18:09:52Z", | ||
"completed_at": "2024-02-11T18:11:49Z", | ||
"name": "Analyze (python)", | ||
"steps": [ | ||
{ | ||
"name": "Set up job", | ||
"status": "completed", | ||
"conclusion": "success", | ||
"number": 1, | ||
"started_at": "2024-02-11T18:09:51.000Z", | ||
"completed_at": "2024-02-11T18:09:55.000Z" | ||
}, | ||
{ | ||
"name": "Checkout repository", | ||
"status": "completed", | ||
"conclusion": "success", | ||
"number": 2, | ||
"started_at": "2024-02-11T18:09:55.000Z", | ||
"completed_at": "2024-02-11T18:09:56.000Z" | ||
}, | ||
{ | ||
"name": "Initialize CodeQL", | ||
"status": "completed", | ||
"conclusion": "success", | ||
"number": 3, | ||
"started_at": "2024-02-11T18:09:56.000Z", | ||
"completed_at": "2024-02-11T18:10:09.000Z" | ||
}, | ||
{ | ||
"name": "Perform CodeQL Analysis", | ||
"status": "completed", | ||
"conclusion": "success", | ||
"number": 4, | ||
"started_at": "2024-02-11T18:10:09.000Z", | ||
"completed_at": "2024-02-11T18:11:46.000Z" | ||
}, | ||
{ | ||
"name": "Post Perform CodeQL Analysis", | ||
"status": "completed", | ||
"conclusion": "success", | ||
"number": 6, | ||
"started_at": "2024-02-11T18:11:47.000Z", | ||
"completed_at": "2024-02-11T18:11:47.000Z" | ||
}, | ||
{ | ||
"name": "Post Initialize CodeQL", | ||
"status": "completed", | ||
"conclusion": "success", | ||
"number": 7, | ||
"started_at": "2024-02-11T18:11:47.000Z", | ||
"completed_at": "2024-02-11T18:11:47.000Z" | ||
}, | ||
{ | ||
"name": "Post Checkout repository", | ||
"status": "completed", | ||
"conclusion": "success", | ||
"number": 8, | ||
"started_at": "2024-02-11T18:11:49.000Z", | ||
"completed_at": "2024-02-11T18:11:49.000Z" | ||
}, | ||
{ | ||
"name": "Complete job", | ||
"status": "completed", | ||
"conclusion": "success", | ||
"number": 9, | ||
"started_at": "2024-02-11T18:11:47.000Z", | ||
"completed_at": "2024-02-11T18:11:47.000Z" | ||
} | ||
], | ||
"check_run_url": "https://api.github.com/repos/cunla/fakeredis-py/check-runs/21454796844", | ||
"labels": [ | ||
"ubuntu-latest" | ||
], | ||
"runner_id": 9, | ||
"runner_name": "GitHub Actions 9", | ||
"runner_group_id": 2, | ||
"runner_group_name": "GitHub Actions" | ||
} |
Oops, something went wrong.