@@ -8,6 +8,7 @@ import com.coder.gateway.sdk.Arch
88import com.coder.gateway.sdk.CoderRestClientService
99import com.coder.gateway.sdk.OS
1010import com.coder.gateway.sdk.v2.models.ProvisionerJobStatus
11+ import com.coder.gateway.sdk.v2.models.Workspace
1112import com.coder.gateway.sdk.v2.models.WorkspaceBuildTransition
1213import com.intellij.ide.IdeBundle
1314import com.intellij.openapi.Disposable
@@ -87,23 +88,7 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
8788 cs.launch {
8889 val workspaceList = withContext(Dispatchers .IO ) {
8990 try {
90- val workspaces = coderClient.workspaces()
91- return @withContext workspaces.flatMap { workspace ->
92- val agents = coderClient.workspaceAgents(workspace)
93- val shouldContainAgentName = agents.size > 1
94- agents.map { agent ->
95- val workspaceName = if (shouldContainAgentName) " ${workspace.name} .${agent.name} " else workspace.name
96- WorkspaceAgentModel (
97- workspaceName,
98- workspace.templateName,
99- workspace.latestBuild.job.status,
100- workspace.latestBuild.workspaceTransition,
101- OS .from(agent.operatingSystem),
102- Arch .from(agent.architecture),
103- agent.directory
104- )
105- }
106- }
91+ return @withContext coderClient.workspaces().collectAgents()
10792 } catch (e: Exception ) {
10893 logger.error(" Could not retrieve workspaces for ${coderClient.me.username} on ${coderClient.coderURL} . Reason: $e " )
10994 emptyList()
@@ -115,6 +100,30 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
115100 }
116101 }
117102
103+ private fun List<Workspace>.collectAgents (): List <WorkspaceAgentModel > {
104+ return this .flatMap { workspace ->
105+ try {
106+ val agents = coderClient.workspaceAgents(workspace)
107+ val shouldContainAgentName = agents.size > 1
108+ return @flatMap agents.map { agent ->
109+ val workspaceName = if (shouldContainAgentName) " ${workspace.name} .${agent.name} " else workspace.name
110+ WorkspaceAgentModel (
111+ workspaceName,
112+ workspace.templateName,
113+ workspace.latestBuild.job.status,
114+ workspace.latestBuild.workspaceTransition,
115+ OS .from(agent.operatingSystem),
116+ Arch .from(agent.architecture),
117+ agent.directory
118+ )
119+ }
120+ } catch (e: Exception ) {
121+ logger.error(" Skipping workspace ${workspace.name} because we could not retrieve the agent(s). Reason: $e " )
122+ emptyList()
123+ }
124+ }
125+ }
126+
118127 override fun onNext (wizardModel : CoderWorkspacesWizardModel ): Boolean {
119128 val workspace = tableOfWorkspaces.selectedObject
120129 if (workspace != null ) {
0 commit comments