From 5d600e557026db6849413a4561c0bcdf80a2f42f Mon Sep 17 00:00:00 2001 From: Daniel M Date: Wed, 10 Apr 2024 16:12:31 -0400 Subject: [PATCH] fix:JobsLoadingModelListener --- .../com/dsoftware/ghmanager/api/GithubApi.kt | 5 ++++- .../ghmanager/data/JobsLoadingModelListener.kt | 14 +------------- .../data/WorkflowDataContextService.kt | 2 +- .../data/WorkflowRunSelectionContext.kt | 6 ++++-- .../ghmanager/data/providers/DataProvider.kt | 5 ++--- .../data/providers/JobsDataProvider.kt | 9 ++------- .../ghmanager/data/providers/LogDataProvider.kt | 3 +-- .../dsoftware/ghmanager/ui/RepoTabController.kt | 10 +++++----- .../ghmanager/ui/panels/JobsListPanel.kt | 17 ++++++----------- src/main/resources/messages/messages.properties | 1 + 10 files changed, 27 insertions(+), 45 deletions(-) diff --git a/src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt b/src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt index 0310d16..c2de71e 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt @@ -64,7 +64,10 @@ object GithubApi : GithubApiRequests.Entity("/repos") { } - fun getWorkflowRunJobs(url: String) = get( + fun getJobsForWorkFlowRun(url: String): GithubApiRequest +// { throw GithubStatusCodeException("Not found", 404) +// } + = get( url, "Get workflow-run jobs", pagination = GithubRequestPagination(1) ) diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/JobsLoadingModelListener.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/JobsLoadingModelListener.kt index f6b6348..b731aed 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/JobsLoadingModelListener.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/JobsLoadingModelListener.kt @@ -12,15 +12,11 @@ import org.jetbrains.plugins.github.pullrequest.ui.GHLoadingModel class JobsLoadingModelListener( workflowRunDisposable: Disposable, - dataProviderModel: SingleValueModel, - runSelectionHolder: WorkflowRunListSelectionHolder, + dataProviderModel: SingleValueModel ) : GHLoadingModel.StateChangeListener { - val jobsModel = SingleValueModel(null) val jobsLoadingModel = GHCompletableFutureLoadingModel(workflowRunDisposable) init { - runSelectionHolder.addSelectionChangeListener(workflowRunDisposable, this::setValue) - jobsLoadingModel.addStateChangeListener(this) var listenerDisposable: Disposable? = null dataProviderModel.addAndInvokeListener { provider -> jobsLoadingModel.future = null @@ -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() - } diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt index 6e9f602..4655cc9 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt @@ -41,7 +41,7 @@ class WorkflowDataContextService(private val project: Project) { toolWindow: ToolWindow, ): CompletableFuture { 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) { diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunSelectionContext.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunSelectionContext.kt index cca7fba..8b716e5 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunSelectionContext.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunSelectionContext.kt @@ -112,7 +112,7 @@ class WorkflowRunSelectionContext internal constructor( } fun createDataProvider(request: GithubApiRequest): DataProvider { - return DataProvider(requestExecutor, request, null) + return DataProvider(requestExecutor, request) } fun getCurrentAccountGHUser(): GHUser { @@ -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 { diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/DataProvider.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/providers/DataProvider.kt index 84ad237..9bc8225 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/DataProvider.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/providers/DataProvider.kt @@ -15,7 +15,6 @@ import java.util.EventListener open class DataProvider( private val requestExecutor: GhApiRequestExecutor, private val githubApiRequest: GithubApiRequest, - private val errorValue: T?, ) { private val runChangesEventDispatcher = EventDispatcher.create(DataProviderChangeListener::class.java) private val progressManager = ProgressManager.getInstance() @@ -29,10 +28,10 @@ open class DataProvider( 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 } } diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/JobsDataProvider.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/providers/JobsDataProvider.kt index 0d979a4..31f3c1a 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/JobsDataProvider.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/providers/JobsDataProvider.kt @@ -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( - requestExecutor, - GithubApi.getWorkflowRunJobs(jobsUrl), - WorkflowRunJobs(0, emptyList()) +class JobsDataProvider(requestExecutor: GhApiRequestExecutor, jobsUrl: String) : DataProvider( + requestExecutor, GithubApi.getJobsForWorkFlowRun(jobsUrl) ) \ No newline at end of file diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/LogDataProvider.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/providers/LogDataProvider.kt index 326c796..b17a589 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/LogDataProvider.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/providers/LogDataProvider.kt @@ -9,6 +9,5 @@ class LogDataProvider( job: Job ) : DataProvider( requestExecutor, - GithubApi.getLogForSingleJob(job), - null + GithubApi.getLogForSingleJob(job) ) \ No newline at end of file diff --git a/src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt b/src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt index 8744d77..cb36316 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt @@ -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 @@ -139,9 +141,7 @@ class RepoTabController( private fun createJobsPanel(selectedRunContext: WorkflowRunSelectionContext): JComponent { val jobsLoadingModel = JobsLoadingModelListener( - selectedRunContext.selectedRunDisposable, - selectedRunContext.jobDataProviderLoadModel, - selectedRunContext.runSelectionHolder + selectedRunContext.selectedRunDisposable, selectedRunContext.jobDataProviderLoadModel ) val jobsPanel = GHLoadingPanelFactory( @@ -149,10 +149,10 @@ class RepoTabController( 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, ) diff --git a/src/main/kotlin/com/dsoftware/ghmanager/ui/panels/JobsListPanel.kt b/src/main/kotlin/com/dsoftware/ghmanager/ui/panels/JobsListPanel.kt index 877c504..02ccd6c 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/ui/panels/JobsListPanel.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/ui/panels/JobsListPanel.kt @@ -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 @@ -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 @@ -27,7 +29,7 @@ import javax.swing.ScrollPaneConstants class JobsListPanel( parentDisposable: Disposable, - jobValueModel: SingleValueModel, + jobs: WorkflowRunJobs, private val runSelectionContext: WorkflowRunSelectionContext, private val infoInNewLine: Boolean ) : BorderLayoutPanel(), Disposable { @@ -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, @@ -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): String { diff --git a/src/main/resources/messages/messages.properties b/src/main/resources/messages/messages.properties index 9b833e0..5373ac8 100644 --- a/src/main/resources/messages/messages.properties +++ b/src/main/resources/messages/messages.properties @@ -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