Skip to content

Commit

Permalink
fix:data for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Feb 11, 2024
1 parent 239789f commit 8e6561b
Show file tree
Hide file tree
Showing 13 changed files with 326 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import java.nio.charset.StandardCharsets
import java.util.TreeMap
import java.util.zip.ZipInputStream

class GetRunLogRequest(url: String) : GithubApiRequest.Get<GitHubLog>(url) {
private lateinit var workflowInfo: GitHubLog
class GetRunLogRequest(url: String) : GithubApiRequest.Get<WorkflowRunLog>(url) {
private lateinit var workflowInfo: WorkflowRunLog

override fun extractResult(response: GithubApiResponse): GitHubLog {
override fun extractResult(response: GithubApiResponse): WorkflowRunLog {
LOG.debug("extracting result for $url")
return response.handleBody {
workflowInfo = extractFromStream(it)
Expand All @@ -23,7 +23,7 @@ class GetRunLogRequest(url: String) : GithubApiRequest.Get<GitHubLog>(url) {

companion object {
private val LOG = logger<GetRunLogRequest>()
fun extractFromStream(inputStream: InputStream): GitHubLog {
fun extractFromStream(inputStream: InputStream): WorkflowRunLog {
val content = HashMap<String, TreeMap<Int, String>>()
try {
ZipInputStream(inputStream).use {
Expand Down
14 changes: 6 additions & 8 deletions src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dsoftware.ghmanager.api

import com.dsoftware.ghmanager.api.model.WorkflowRunJobsList
import com.dsoftware.ghmanager.api.model.WorkflowRunJobs
import com.dsoftware.ghmanager.api.model.WorkflowRuns
import com.dsoftware.ghmanager.api.model.WorkflowTypes
import com.dsoftware.ghmanager.data.RepositoryCoordinates
Expand All @@ -18,16 +18,14 @@ data class WorkflowRunFilter(
val event: String? = null,
val workflowId: Long? = null,
)
typealias GitHubLog = Map<String, Map<Int, String>>
typealias WorkflowRunLog = Map<String, Map<Int, String>>

object GithubApi : GithubApiRequests.Entity("/repos") {
private val LOG = logger<GithubApi>()
fun getDownloadUrlForWorkflowLog(url: String) = GetRunLogRequest(url)
.withOperationName("Download Workflow log")
fun getDownloadUrlForWorkflowLog(url: String) = GetRunLogRequest(url).withOperationName("Download Workflow log")

fun postUrl(name:String,url: String, data: Any = Object()) =
GithubApiRequest.Post.Json(url, data, Object::class.java, null)
.withOperationName(name)
fun postUrl(name: String, url: String, data: Any = Object()) =
GithubApiRequest.Post.Json(url, data, Object::class.java, null).withOperationName(name)

fun getWorkflowTypes(
coordinates: RepositoryCoordinates,
Expand Down Expand Up @@ -66,7 +64,7 @@ object GithubApi : GithubApiRequests.Entity("/repos") {
}


fun getWorkflowRunJobs(url: String) = get<WorkflowRunJobsList>(
fun getWorkflowRunJobs(url: String) = get<WorkflowRunJobs>(
url, "Get workflow-run jobs", pagination = GithubRequestPagination(1)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.dsoftware.ghmanager.api.model
import com.fasterxml.jackson.annotation.JsonFormat
import java.util.Date

data class WorkflowRunJobsList(
data class WorkflowRunJobs(
val totalCount: Int,
val jobs: List<Job>
)
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/dsoftware/ghmanager/data/DataProviders.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.dsoftware.ghmanager.data

import com.dsoftware.ghmanager.api.GitHubLog
import com.dsoftware.ghmanager.api.WorkflowRunLog
import com.dsoftware.ghmanager.api.GithubApi
import com.dsoftware.ghmanager.api.model.WorkflowRunJobsList
import com.dsoftware.ghmanager.api.model.WorkflowRunJobs
import com.intellij.openapi.Disposable
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.progress.ProgressManager
Expand Down Expand Up @@ -66,7 +66,7 @@ class WorkflowRunLogsDataProvider(
progressManager: ProgressManager,
requestExecutor: GithubApiRequestExecutor,
logsUrl: String,
) : DataProvider<GitHubLog>(
) : DataProvider<WorkflowRunLog>(
progressManager,
requestExecutor,
GithubApi.getDownloadUrlForWorkflowLog(logsUrl),
Expand All @@ -78,9 +78,9 @@ class WorkflowRunJobsDataProvider(
progressManager: ProgressManager,
requestExecutor: GithubApiRequestExecutor,
jobsUrl: String
) : DataProvider<WorkflowRunJobsList>(
) : DataProvider<WorkflowRunJobs>(
progressManager,
requestExecutor,
GithubApi.getWorkflowRunJobs(jobsUrl),
WorkflowRunJobsList(0, emptyList())
WorkflowRunJobs(0, emptyList())
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dsoftware.ghmanager.data

import com.dsoftware.ghmanager.api.model.WorkflowRunJobsList
import com.dsoftware.ghmanager.api.model.WorkflowRunJobs
import com.intellij.collaboration.ui.SingleValueModel
import com.intellij.openapi.Disposable
import com.intellij.openapi.util.Disposer
Expand All @@ -13,8 +13,8 @@ class JobsLoadingModelListener(
dataProviderModel: SingleValueModel<WorkflowRunJobsDataProvider?>,
runSelectionHolder: WorkflowRunListSelectionHolder,
) : GHLoadingModel.StateChangeListener {
val jobsModel = SingleValueModel<WorkflowRunJobsList?>(null)
val jobsLoadingModel = GHCompletableFutureLoadingModel<WorkflowRunJobsList>(workflowRunDisposable)
val jobsModel = SingleValueModel<WorkflowRunJobs?>(null)
val jobsLoadingModel = GHCompletableFutureLoadingModel<WorkflowRunJobs>(workflowRunDisposable)

init {
runSelectionHolder.addSelectionChangeListener(workflowRunDisposable, this::setValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.dsoftware.ghmanager.data
import com.dsoftware.ghmanager.Constants.LOG_MSG_JOB_IN_PROGRESS
import com.dsoftware.ghmanager.Constants.LOG_MSG_MISSING
import com.dsoftware.ghmanager.Constants.LOG_MSG_PICK_JOB
import com.dsoftware.ghmanager.api.GitHubLog
import com.dsoftware.ghmanager.api.WorkflowRunLog
import com.dsoftware.ghmanager.api.model.Job
import com.dsoftware.ghmanager.api.model.JobStep
import com.intellij.collaboration.ui.SingleValueModel
Expand All @@ -20,7 +20,7 @@ class LogLoadingModelListener(
private val jobsSelectionHolder: JobListSelectionHolder,
) : GHLoadingModel.StateChangeListener {
val logModel = SingleValueModel<String?>(null)
val logsLoadingModel = GHCompletableFutureLoadingModel<GitHubLog>(workflowRunDisposable)
val logsLoadingModel = GHCompletableFutureLoadingModel<WorkflowRunLog>(workflowRunDisposable)

init {
jobsSelectionHolder.addSelectionChangeListener(workflowRunDisposable, this::setLogValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.dsoftware.ghmanager.ui.panels

import com.dsoftware.ghmanager.actions.ActionKeys
import com.dsoftware.ghmanager.api.model.Job
import com.dsoftware.ghmanager.api.model.WorkflowRunJobsList
import com.dsoftware.ghmanager.api.model.WorkflowRunJobs
import com.dsoftware.ghmanager.data.WorkflowRunSelectionContext
import com.dsoftware.ghmanager.ui.ToolbarUtil
import com.intellij.collaboration.ui.SingleValueModel
Expand Down Expand Up @@ -134,7 +134,7 @@ class JobListComponent(
private val actionManager = ActionManager.getInstance()

fun createJobsListComponent(
jobValueModel: SingleValueModel<WorkflowRunJobsList?>,
jobValueModel: SingleValueModel<WorkflowRunJobs?>,
runSelectionContext: WorkflowRunSelectionContext,
infoInNewLine: Boolean,
): Pair<HtmlInfoPanel, JComponent> {
Expand Down
26 changes: 26 additions & 0 deletions src/test/resources/branches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"name": "detached",
"commit": {
"sha": "048dfc02d42e657199e636e0d60df56389a8078c",
"url": "https://api.github.com/repos/cunla/ghactions-manager/commits/048dfc02d42e657199e636e0d60df56389a8078c"
},
"protected": false
},
{
"name": "group_by_workflow",
"commit": {
"sha": "6e033c6e63d8b91e1430cce275110b4438d59f10",
"url": "https://api.github.com/repos/cunla/ghactions-manager/commits/6e033c6e63d8b91e1430cce275110b4438d59f10"
},
"protected": false
},
{
"name": "master",
"commit": {
"sha": "239789f77d6706067bd8dab32ec4155e1cfd9962",
"url": "https://api.github.com/repos/cunla/ghactions-manager/commits/239789f77d6706067bd8dab32ec4155e1cfd9962"
},
"protected": true
}
]
Loading

0 comments on commit 8e6561b

Please sign in to comment.