@@ -8,6 +8,7 @@ import com.coder.gateway.sdk.Arch
8
8
import com.coder.gateway.sdk.CoderRestClientService
9
9
import com.coder.gateway.sdk.OS
10
10
import com.coder.gateway.sdk.v2.models.ProvisionerJobStatus
11
+ import com.coder.gateway.sdk.v2.models.Workspace
11
12
import com.coder.gateway.sdk.v2.models.WorkspaceBuildTransition
12
13
import com.intellij.ide.IdeBundle
13
14
import com.intellij.openapi.Disposable
@@ -87,23 +88,7 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
87
88
cs.launch {
88
89
val workspaceList = withContext(Dispatchers .IO ) {
89
90
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()
107
92
} catch (e: Exception ) {
108
93
logger.error(" Could not retrieve workspaces for ${coderClient.me.username} on ${coderClient.coderURL} . Reason: $e " )
109
94
emptyList()
@@ -115,6 +100,30 @@ class CoderWorkspacesStepView : CoderWorkspacesWizardStep, Disposable {
115
100
}
116
101
}
117
102
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
+
118
127
override fun onNext (wizardModel : CoderWorkspacesWizardModel ): Boolean {
119
128
val workspace = tableOfWorkspaces.selectedObject
120
129
if (workspace != null ) {
0 commit comments