From 90ac9b196425cb91aef1afdf825f3e6d824dfb42 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Wed, 10 Apr 2024 16:58:57 -0400 Subject: [PATCH] fix:JobsLoadingModelListener --- .../ghmanager/actions/PostWorkflowActions.kt | 2 +- .../com/dsoftware/ghmanager/api/GithubApi.kt | 5 +---- .../data/JobsLoadingModelListener.kt | 4 ++-- .../ghmanager/data/LogLoadingModelListener.kt | 4 ++-- .../ghmanager/data/providers/DataProvider.kt | 20 ++++++++++++++----- .../data/providers/JobsDataProvider.kt | 9 --------- .../data/providers/LogDataProvider.kt | 13 ------------ 7 files changed, 21 insertions(+), 36 deletions(-) delete mode 100644 src/main/kotlin/com/dsoftware/ghmanager/data/providers/JobsDataProvider.kt delete mode 100644 src/main/kotlin/com/dsoftware/ghmanager/data/providers/LogDataProvider.kt diff --git a/src/main/kotlin/com/dsoftware/ghmanager/actions/PostWorkflowActions.kt b/src/main/kotlin/com/dsoftware/ghmanager/actions/PostWorkflowActions.kt index 771fd51..d576c4f 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/actions/PostWorkflowActions.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/actions/PostWorkflowActions.kt @@ -33,7 +33,7 @@ abstract class PostUrlAction( getUrl(e.dataContext)?.let { val request = GithubApi.postUrl(text, it, getData(e.dataContext)) val context = e.getRequiredData(ActionKeys.ACTION_DATA_CONTEXT) - val future = context.createDataProvider(request).request + val future = context.createDataProvider(request).processValue future.thenApply { afterPostUrl() } diff --git a/src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt b/src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt index c2de71e..2af1aa8 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/api/GithubApi.kt @@ -64,10 +64,7 @@ object GithubApi : GithubApiRequests.Entity("/repos") { } - fun getJobsForWorkFlowRun(url: String): GithubApiRequest -// { throw GithubStatusCodeException("Not found", 404) -// } - = get( + fun getJobsForWorkFlowRun(url: String): GithubApiRequest = 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 b731aed..2d28fc1 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/JobsLoadingModelListener.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/JobsLoadingModelListener.kt @@ -24,14 +24,14 @@ class JobsLoadingModelListener( listenerDisposable = null provider?.let { - jobsLoadingModel.future = it.request + jobsLoadingModel.future = it.processValue val disposable = Disposer.newDisposable().apply { Disposer.register(jobsLoadingModel, this) } it.addRunChangesListener(disposable, object : DataProvider.DataProviderChangeListener { override fun changed() { - jobsLoadingModel.future = it.request + jobsLoadingModel.future = it.processValue } }) listenerDisposable = disposable diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/LogLoadingModelListener.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/LogLoadingModelListener.kt index 83d5941..6e18731 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/LogLoadingModelListener.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/LogLoadingModelListener.kt @@ -35,7 +35,7 @@ class LogLoadingModelListener( var listenerDisposable: Disposable? = null logDataProvider.addAndInvokeListener { provider -> logsLoadingModel.future = null - logsLoadingModel.future = provider?.request + logsLoadingModel.future = provider?.processValue listenerDisposable = listenerDisposable?.let { Disposer.dispose(it) null @@ -47,7 +47,7 @@ class LogLoadingModelListener( it.addRunChangesListener(newDisposable, object : DataProvider.DataProviderChangeListener { override fun changed() { - logsLoadingModel.future = it.request + logsLoadingModel.future = it.processValue } }) listenerDisposable = newDisposable 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 9bc8225..e08208b 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/DataProvider.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/providers/DataProvider.kt @@ -1,6 +1,9 @@ package com.dsoftware.ghmanager.data.providers import com.dsoftware.ghmanager.api.GhApiRequestExecutor +import com.dsoftware.ghmanager.api.GithubApi +import com.dsoftware.ghmanager.api.model.Job +import com.dsoftware.ghmanager.api.model.WorkflowRunJobs import com.intellij.collaboration.async.CompletableFutureUtil.submitIOTask import com.intellij.collaboration.util.ProgressIndicatorsProvider import com.intellij.openapi.Disposable @@ -20,7 +23,7 @@ open class DataProvider( private val progressManager = ProgressManager.getInstance() private val indicatorsProvider: ProgressIndicatorsProvider = ProgressIndicatorsProvider() - private val processValue = progressManager.submitIOTask(indicatorsProvider, true) { + val processValue = progressManager.submitIOTask(indicatorsProvider, true) { try { LOG.info("Executing ${githubApiRequest.url}") val request = githubApiRequest @@ -35,9 +38,6 @@ open class DataProvider( } } - val request - get() = processValue - fun url(): String = githubApiRequest.url fun reload() { @@ -55,4 +55,14 @@ open class DataProvider( companion object { private val LOG = thisLogger() } -} \ No newline at end of file +} + + +class JobsDataProvider(requestExecutor: GhApiRequestExecutor, jobsUrl: String) : DataProvider( + requestExecutor, GithubApi.getJobsForWorkFlowRun(jobsUrl) +) + + +class LogDataProvider(requestExecutor: GhApiRequestExecutor, job: Job) : DataProvider( + requestExecutor, GithubApi.getLogForSingleJob(job) +) \ No newline at end of file diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/JobsDataProvider.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/providers/JobsDataProvider.kt deleted file mode 100644 index 31f3c1a..0000000 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/JobsDataProvider.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.dsoftware.ghmanager.data.providers - -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.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 deleted file mode 100644 index b17a589..0000000 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/providers/LogDataProvider.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.dsoftware.ghmanager.data.providers - -import com.dsoftware.ghmanager.api.GhApiRequestExecutor -import com.dsoftware.ghmanager.api.GithubApi -import com.dsoftware.ghmanager.api.model.Job - -class LogDataProvider( - requestExecutor: GhApiRequestExecutor, - job: Job -) : DataProvider( - requestExecutor, - GithubApi.getLogForSingleJob(job) -) \ No newline at end of file