Skip to content

Commit

Permalink
fix:JobsLoadingModelListener
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Apr 10, 2024
1 parent 8f153b8 commit 5d600e5
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 45 deletions.
5 changes: 4 additions & 1 deletion src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ object GithubApi : GithubApiRequests.Entity("/repos") {
}


fun getWorkflowRunJobs(url: String) = get<WorkflowRunJobs>(
fun getJobsForWorkFlowRun(url: String): GithubApiRequest<WorkflowRunJobs>
// { throw GithubStatusCodeException("Not found", 404)
// }
= get<WorkflowRunJobs>(
url, "Get workflow-run jobs", pagination = GithubRequestPagination(1)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ import org.jetbrains.plugins.github.pullrequest.ui.GHLoadingModel

class JobsLoadingModelListener(
workflowRunDisposable: Disposable,
dataProviderModel: SingleValueModel<JobsDataProvider?>,
runSelectionHolder: WorkflowRunListSelectionHolder,
dataProviderModel: SingleValueModel<JobsDataProvider?>
) : GHLoadingModel.StateChangeListener {
val jobsModel = SingleValueModel<WorkflowRunJobs?>(null)
val jobsLoadingModel = GHCompletableFutureLoadingModel<WorkflowRunJobs>(workflowRunDisposable)

init {
runSelectionHolder.addSelectionChangeListener(workflowRunDisposable, this::setValue)
jobsLoadingModel.addStateChangeListener(this)
var listenerDisposable: Disposable? = null
dataProviderModel.addAndInvokeListener { provider ->
jobsLoadingModel.future = null
Expand All @@ -44,12 +40,4 @@ class JobsLoadingModelListener(

}

private fun setValue() {
jobsModel.value = jobsLoadingModel.result
}

override fun onLoadingCompleted() = setValue()
override fun onLoadingStarted() = setValue()
override fun onReset() = setValue()

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class WorkflowDataContextService(private val project: Project) {
toolWindow: ToolWindow,
): CompletableFuture<WorkflowRunSelectionContext> {
return repositories.getOrPut(repositoryMapping.remote.url) {
LazyCancellableBackgroundProcessValue.create(ProgressManager.getInstance()) { indicator ->
LazyCancellableBackgroundProcessValue.create(ProgressManager.getInstance()) {
LOG.debug("Creating data context for ${repositoryMapping.remote.url}")
try {
val token = if (settingsService.state.useGitHubSettings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class WorkflowRunSelectionContext internal constructor(
}

fun <T> createDataProvider(request: GithubApiRequest<T>): DataProvider<T> {
return DataProvider(requestExecutor, request, null)
return DataProvider(requestExecutor, request)
}

fun getCurrentAccountGHUser(): GHUser {
Expand Down Expand Up @@ -140,8 +140,10 @@ class WorkflowRunSelectionContext internal constructor(
runsListLoader.reset()
runsListLoader.loadMore(true)
jobDataProviderLoadModel.value = null
jobDataProviderLoadModel.value = null
runSelectionHolder.selection = null
jobSelectionHolder.selection = null
selectedRunDisposable.dispose()
selectedJobDisposable.dispose()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import java.util.EventListener
open class DataProvider<T>(
private val requestExecutor: GhApiRequestExecutor,
private val githubApiRequest: GithubApiRequest<T>,
private val errorValue: T?,
) {
private val runChangesEventDispatcher = EventDispatcher.create(DataProviderChangeListener::class.java)
private val progressManager = ProgressManager.getInstance()
Expand All @@ -29,10 +28,10 @@ open class DataProvider<T>(
response
} catch (e: GithubStatusCodeException) {
LOG.warn("Error when getting $githubApiRequest.url: status code ${e.statusCode}: ${e.message}")
errorValue ?: throw e
throw e
} catch (ioe: IOException) {
LOG.warn("Error when getting $githubApiRequest.url: $ioe")
errorValue ?: throw ioe
throw ioe
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import com.dsoftware.ghmanager.api.GhApiRequestExecutor
import com.dsoftware.ghmanager.api.GithubApi
import com.dsoftware.ghmanager.api.model.WorkflowRunJobs

class JobsDataProvider(
requestExecutor: GhApiRequestExecutor,
jobsUrl: String
) : DataProvider<WorkflowRunJobs>(
requestExecutor,
GithubApi.getWorkflowRunJobs(jobsUrl),
WorkflowRunJobs(0, emptyList())
class JobsDataProvider(requestExecutor: GhApiRequestExecutor, jobsUrl: String) : DataProvider<WorkflowRunJobs>(
requestExecutor, GithubApi.getJobsForWorkFlowRun(jobsUrl)
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ class LogDataProvider(
job: Job
) : DataProvider<String>(
requestExecutor,
GithubApi.getLogForSingleJob(job),
null
GithubApi.getLogForSingleJob(job)
)
10 changes: 5 additions & 5 deletions src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package com.dsoftware.ghmanager.ui
import com.dsoftware.ghmanager.actions.ActionKeys
import com.dsoftware.ghmanager.data.JobsLoadingModelListener
import com.dsoftware.ghmanager.data.LogLoadingModelListener
import com.dsoftware.ghmanager.data.LogValue
import com.dsoftware.ghmanager.data.LogValueStatus
import com.dsoftware.ghmanager.data.WorkflowDataContextService
import com.dsoftware.ghmanager.data.WorkflowRunSelectionContext
import com.dsoftware.ghmanager.i18n.MessagesBundle.message
Expand Down Expand Up @@ -139,20 +141,18 @@ class RepoTabController(

private fun createJobsPanel(selectedRunContext: WorkflowRunSelectionContext): JComponent {
val jobsLoadingModel = JobsLoadingModelListener(
selectedRunContext.selectedRunDisposable,
selectedRunContext.jobDataProviderLoadModel,
selectedRunContext.runSelectionHolder
selectedRunContext.selectedRunDisposable, selectedRunContext.jobDataProviderLoadModel
)

val jobsPanel = GHLoadingPanelFactory(
jobsLoadingModel.jobsLoadingModel,
message("panel.jobs.not-loading"),
message("panel.jobs.loading-error"),
selectedRunContext.getLoadingErrorHandler { selectedRunContext.jobDataProviderLoadModel.value = null }
).create { _, _ ->
).create { _, jobs ->
JobsListPanel(
checkedDisposable,
jobsLoadingModel.jobsModel,
jobs,
selectedRunContext,
infoInNewLine = !settingsService.state.jobListAboveLogs,
)
Expand Down
17 changes: 6 additions & 11 deletions src/main/kotlin/com/dsoftware/ghmanager/ui/panels/JobsListPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package com.dsoftware.ghmanager.ui.panels
import com.dsoftware.ghmanager.api.model.Job
import com.dsoftware.ghmanager.api.model.Status
import com.dsoftware.ghmanager.api.model.WorkflowRunJobs
import com.dsoftware.ghmanager.data.JobsLoadingModelListener
import com.dsoftware.ghmanager.data.WorkflowRunSelectionContext
import com.dsoftware.ghmanager.i18n.MessagesBundle.message
import com.dsoftware.ghmanager.ui.ToolbarUtil
import com.intellij.collaboration.ui.SingleValueModel
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.ActionManager
Expand All @@ -19,6 +19,8 @@ import com.intellij.ui.PopupHandler
import com.intellij.ui.ScrollPaneFactory
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.components.BorderLayoutPanel
import org.jetbrains.plugins.github.pullrequest.ui.GHCompletableFutureLoadingModel
import org.jetbrains.plugins.github.pullrequest.ui.GHLoadingModel
import org.jetbrains.plugins.github.ui.HtmlInfoPanel
import java.awt.BorderLayout
import java.awt.Component
Expand All @@ -27,7 +29,7 @@ import javax.swing.ScrollPaneConstants

class JobsListPanel(
parentDisposable: Disposable,
jobValueModel: SingleValueModel<WorkflowRunJobs?>,
jobs: WorkflowRunJobs,
private val runSelectionContext: WorkflowRunSelectionContext,
private val infoInNewLine: Boolean
) : BorderLayoutPanel(), Disposable {
Expand All @@ -37,7 +39,6 @@ class JobsListPanel(
init {
Disposer.register(parentDisposable, this)
jobsListModel.removeAll()
jobValueModel.addAndInvokeListener { updatePanel(it) }
val scrollPane = ScrollPaneFactory.createScrollPane(
createListComponent(),
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
Expand All @@ -51,15 +52,9 @@ class JobsListPanel(
isOpaque = false
add(topInfoPanel, BorderLayout.NORTH)
add(scrollPane, BorderLayout.CENTER)
}

private fun updatePanel(newJobs: WorkflowRunJobs?) {
jobsListModel.removeAll()
topInfoPanel.setInfo("")
newJobs?.let {
jobsListModel.add(it.jobs)
topInfoPanel.setInfo(infoTitleString(it.jobs))
}
jobsListModel.add(jobs.jobs)
topInfoPanel.setInfo(infoTitleString(jobs.jobs))
}

private fun infoTitleString(jobs: List<Job>): String {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ github.status.code.error=GitHub API returned status code {0}, message ''{1}''
# Jobs panel
panel.jobs.not-loading=Select a workflow to show list of jobs
panel.jobs.loading-error=Can''t load jobs list from GitHub for the selected workflow-run
panel.jobs.info.error=Can''t load jobs list from GitHub for the selected workflow-run, got error: {0}
panel.jobs.info.no-jobs=No jobs in workflow run
panel.jobs.job-status.queued=Job is queued
panel.jobs.job-status.in-progress=Job is running
Expand Down

0 comments on commit 5d600e5

Please sign in to comment.