From b0b0d6dc19707bbfee15b4cf44108d8ba2d867f9 Mon Sep 17 00:00:00 2001 From: Daniel M Date: Sun, 10 Mar 2024 12:09:16 -0400 Subject: [PATCH] cleanup --- .../data/WorkflowDataContextService.kt | 6 +-- .../ghmanager/data/WorkflowRunListLoader.kt | 2 +- .../data/WorkflowRunSelectionContext.kt | 46 +++++++++---------- .../ui/GhActionsMgrToolWindowContent.kt | 3 +- .../ghmanager/ui/RepoTabController.kt | 19 ++------ .../ghmanager/GitHubActionsManagerBaseTest.kt | 2 + 6 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt index f5bb637..2b78b65 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowDataContextService.kt @@ -56,9 +56,6 @@ class WorkflowDataContextService(private val project: Project) { } else { settingsService.state.apiToken } - - val requestExecutor = GithubApiRequestExecutor.Factory.getInstance().create(token = token) - val singleRunDataLoader = SingleRunDataLoader(requestExecutor) if (checkedDisposable.isDisposed) { throw ProcessCanceledException( RuntimeException("Skipped creating data context for ${repositoryMapping.remote.url} because it was disposed") @@ -68,9 +65,8 @@ class WorkflowDataContextService(private val project: Project) { checkedDisposable, toolWindow, account, - singleRunDataLoader, repositoryMapping, - requestExecutor, + token, ) } catch (e: Exception) { if (e !is ProcessCanceledException) diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunListLoader.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunListLoader.kt index 042f350..240587d 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunListLoader.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunListLoader.kt @@ -192,7 +192,7 @@ class WorkflowRunListLoader( val wfRunsResponse = try { requestExecutor.execute(indicator, request) } catch (e: Exception) { - LOG.error("Error loading workflow runs") + LOG.error("Error loading workflow runs from ${request.url}") throw e } totalCount = wfRunsResponse.totalCount diff --git a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunSelectionContext.kt b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunSelectionContext.kt index 6b4798a..32509c7 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunSelectionContext.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/data/WorkflowRunSelectionContext.kt @@ -26,54 +26,54 @@ class WorkflowRunSelectionContext internal constructor( parentDisposable: CheckedDisposable, val toolWindow: ToolWindow, val account: GithubAccount, - val dataLoader: SingleRunDataLoader, val repositoryMapping: GHGitRepositoryMapping, - val requestExecutor: GithubApiRequestExecutor, + token:String, val runSelectionHolder: WorkflowRunListSelectionHolder = WorkflowRunListSelectionHolder(), val jobSelectionHolder: JobListSelectionHolder = JobListSelectionHolder(), ) : Disposable.Parent { private val task: ScheduledFuture<*> - private val fullPath = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(repositoryMapping.remote.url) - ?: throw IllegalArgumentException( - "Invalid GitHub Repository URL - ${repositoryMapping.remote.url} is not a GitHub repository" - ) - private val selectedWfRun: WorkflowRun? - get() = runSelectionHolder.selection - val runsListLoader: WorkflowRunListLoader = WorkflowRunListLoader( - toolWindow, - this, - requestExecutor, - RepositoryCoordinates(account.server, fullPath), - WorkflowRunFilter(), - ) + val runsListLoader: WorkflowRunListLoader val runsListModel: CollectionListModel get() = runsListLoader.workflowRunsListModel + val requestExecutor = GithubApiRequestExecutor.Factory.getInstance().create(token = token) var selectedRunDisposable = Disposer.newDisposable("Selected run disposable") val jobDataProviderLoadModel: SingleValueModel = SingleValueModel(null) val jobsDataProvider: WorkflowRunJobsDataProvider? - get() = selectedWfRun?.let { dataLoader.getJobsDataProvider(it) } + get() = runSelectionHolder.selection?.let { dataLoader.getJobsDataProvider(it) } + var selectedJobDisposable = Disposer.newDisposable("Selected job disposable") - private val selectedJob: Job? - get() = jobSelectionHolder.selection val jobLogDataProviderLoadModel: SingleValueModel = SingleValueModel(null) + + val dataLoader = SingleRunDataLoader(requestExecutor) val logDataProvider: JobLogDataProvider? - get() = selectedJob?.let { dataLoader.getJobLogDataProvider(it) } + get() = jobSelectionHolder.selection?.let { dataLoader.getJobLogDataProvider(it) } val currentBranchName: String? get() = repositoryMapping.gitRepository.currentBranchName init { Disposer.register(parentDisposable, this) + val fullPath = GithubUrlUtil.getUserAndRepositoryFromRemoteUrl(repositoryMapping.remote.url) + ?: throw IllegalArgumentException( + "Invalid GitHub Repository URL - ${repositoryMapping.remote.url} is not a GitHub repository" + ) + runsListLoader = WorkflowRunListLoader( + toolWindow, + this, + requestExecutor, + RepositoryCoordinates(account.server, fullPath), + WorkflowRunFilter(), + ) task = ToolbarUtil.executeTaskAtSettingsFrequency(toolWindow.project) { - if (selectedWfRun == null) { + if (runSelectionHolder.selection == null) { return@executeTaskAtSettingsFrequency } - LOG.info("Checking updated status for $selectedWfRun.id") - if (selectedWfRun?.status != "completed") { + LOG.info("Checking updated status for $runSelectionHolder.selection.id") + if (runSelectionHolder.selection?.status != "completed") { jobsDataProvider?.reload() } - if (selectedJob?.status != "completed") { + if (jobSelectionHolder.selection?.status != "completed") { logDataProvider?.reload() } } diff --git a/src/main/kotlin/com/dsoftware/ghmanager/ui/GhActionsMgrToolWindowContent.kt b/src/main/kotlin/com/dsoftware/ghmanager/ui/GhActionsMgrToolWindowContent.kt index ac2fc72..67443ba 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/ui/GhActionsMgrToolWindowContent.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/ui/GhActionsMgrToolWindowContent.kt @@ -114,7 +114,6 @@ class GhActionsMgrToolWindowContent(val toolWindow: ToolWindow) : Disposable { private fun createRepoWorkflowsPanels(toolWindow: ToolWindow) { val actionManager = ActionManager.getInstance() toolWindow.setAdditionalGearActions(DefaultActionGroup(actionManager.getAction("Github.Actions.Manager.Settings.Open"))) - val dataContextRepository = toolWindow.project.service() val reposToHavePanel = ghActionsService.knownRepositories.filter { !settingsService.state.useCustomRepos || (settingsService.state.customRepos[it.remote.url]?.included ?: false) @@ -143,7 +142,7 @@ class GhActionsMgrToolWindowContent(val toolWindow: ToolWindow) : Disposable { displayName = repoSettings.customName.ifEmpty { repo.repositoryPath } } val controller = RepoTabController( - repo, ghAccount, dataContextRepository, tab.disposer!!, toolWindow, + repo, ghAccount, tab.disposer!!, toolWindow, ) tab.component.apply { layout = BorderLayout() diff --git a/src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt b/src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt index cc84c33..2146bd7 100644 --- a/src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt +++ b/src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt @@ -36,13 +36,13 @@ import kotlin.properties.Delegates class RepoTabController( repositoryMapping: GHGitRepositoryMapping, private val ghAccount: GithubAccount, - private val dataContextRepository: WorkflowDataContextService, parentDisposable: Disposable, private val toolWindow: ToolWindow, ) { + private val dataContextRepository = toolWindow.project.service() + private val settingsService = toolWindow.project.service() val loadingModel: GHCompletableFutureLoadingModel val panel: JComponent - private val settingsService = toolWindow.project.service() private val actionManager = ActionManager.getInstance() private var checkedDisposable: CheckedDisposable = Disposer.newCheckedDisposable(parentDisposable, "WorkflowToolWindowTabController") @@ -58,21 +58,12 @@ class RepoTabController( dataContextRepository.clearContext(repositoryMapping) } loadingModel = GHCompletableFutureLoadingModel(checkedDisposable).apply { - future = dataContextRepository.acquireContext( - checkedDisposable, - repositoryMapping, - ghAccount, - toolWindow - ) + future = dataContextRepository.acquireContext(checkedDisposable, repositoryMapping, ghAccount, toolWindow) } val errorHandler = GHApiLoadingErrorHandler(toolWindow.project, ghAccount) { dataContextRepository.clearContext(repositoryMapping) - loadingModel.future = dataContextRepository.acquireContext( - checkedDisposable, - repositoryMapping, - ghAccount, - toolWindow - ) + loadingModel.future = + dataContextRepository.acquireContext(checkedDisposable, repositoryMapping, ghAccount, toolWindow) } panel = GHLoadingPanelFactory( loadingModel, diff --git a/src/test/kotlin/com/dsoftware/ghmanager/GitHubActionsManagerBaseTest.kt b/src/test/kotlin/com/dsoftware/ghmanager/GitHubActionsManagerBaseTest.kt index 435e2c8..1c0e1b3 100644 --- a/src/test/kotlin/com/dsoftware/ghmanager/GitHubActionsManagerBaseTest.kt +++ b/src/test/kotlin/com/dsoftware/ghmanager/GitHubActionsManagerBaseTest.kt @@ -12,6 +12,7 @@ import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.TestApplicationManager import com.intellij.testFramework.common.initTestApplication import com.intellij.testFramework.junit5.RunInEdt +import com.intellij.testFramework.junit5.TestApplication import com.intellij.testFramework.registerServiceInstance import com.intellij.testFramework.rules.ProjectModelExtension import com.intellij.testFramework.waitUntil @@ -37,6 +38,7 @@ import org.junit.jupiter.api.TestInfo import org.junit.jupiter.api.extension.RegisterExtension @RunInEdt(writeIntent = true) +//@TestApplication abstract class GitHubActionsManagerBaseTest { init { initTestApplication()