Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Mar 10, 2024
1 parent 1d5b847 commit b0b0d6d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -68,9 +65,8 @@ class WorkflowDataContextService(private val project: Project) {
checkedDisposable,
toolWindow,
account,
singleRunDataLoader,
repositoryMapping,
requestExecutor,
token,
)
} catch (e: Exception) {
if (e !is ProcessCanceledException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkflowRun>
get() = runsListLoader.workflowRunsListModel

val requestExecutor = GithubApiRequestExecutor.Factory.getInstance().create(token = token)
var selectedRunDisposable = Disposer.newDisposable("Selected run disposable")
val jobDataProviderLoadModel: SingleValueModel<WorkflowRunJobsDataProvider?> = 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<JobLogDataProvider?> = 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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkflowDataContextService>()
val reposToHavePanel = ghActionsService.knownRepositories.filter {
!settingsService.state.useCustomRepos
|| (settingsService.state.customRepos[it.remote.url]?.included ?: false)
Expand Down Expand Up @@ -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()
Expand Down
19 changes: 5 additions & 14 deletions src/main/kotlin/com/dsoftware/ghmanager/ui/RepoTabController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorkflowDataContextService>()
private val settingsService = toolWindow.project.service<GhActionsSettingsService>()
val loadingModel: GHCompletableFutureLoadingModel<WorkflowRunSelectionContext>
val panel: JComponent
private val settingsService = toolWindow.project.service<GhActionsSettingsService>()
private val actionManager = ActionManager.getInstance()
private var checkedDisposable: CheckedDisposable =
Disposer.newCheckedDisposable(parentDisposable, "WorkflowToolWindowTabController")
Expand All @@ -58,21 +58,12 @@ class RepoTabController(
dataContextRepository.clearContext(repositoryMapping)
}
loadingModel = GHCompletableFutureLoadingModel<WorkflowRunSelectionContext>(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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit b0b0d6d

Please sign in to comment.