Skip to content

Commit ed37ab0

Browse files
committed
Simplify workspace status check
Looks like there is already a property that is the composite of the two fields we were checking.
1 parent 68952f9 commit ed37ab0

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed
Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.coder.gateway.models
22

3-
import com.coder.gateway.sdk.v2.models.ProvisionerJobStatus
43
import com.coder.gateway.sdk.v2.models.Workspace
5-
import com.coder.gateway.sdk.v2.models.WorkspaceTransition
4+
import com.coder.gateway.sdk.v2.models.WorkspaceStatus
65
import com.intellij.ui.JBColor
76

87
enum class WorkspaceAgentStatus(val label: String) {
@@ -16,26 +15,22 @@ enum class WorkspaceAgentStatus(val label: String) {
1615
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY
1716
}
1817

18+
// Note that latest_build.status is derived from latest_build.job.status and
19+
// latest_build.job.transition so there is no need to check those.
1920
companion object {
20-
fun from(workspace: Workspace) = when (workspace.latestBuild.job.status) {
21-
ProvisionerJobStatus.PENDING -> QUEUED
22-
ProvisionerJobStatus.RUNNING -> when (workspace.latestBuild.transition) {
23-
WorkspaceTransition.START -> STARTING
24-
WorkspaceTransition.STOP -> STOPPING
25-
WorkspaceTransition.DELETE -> DELETING
26-
}
27-
28-
ProvisionerJobStatus.SUCCEEDED -> when (workspace.latestBuild.transition) {
29-
WorkspaceTransition.START -> RUNNING
30-
WorkspaceTransition.STOP -> STOPPED
31-
WorkspaceTransition.DELETE -> DELETED
32-
}
33-
34-
ProvisionerJobStatus.CANCELING -> CANCELING
35-
ProvisionerJobStatus.CANCELED -> CANCELED
36-
ProvisionerJobStatus.FAILED -> FAILED
21+
fun from(workspace: Workspace, agent: WorkspaceAgentModel) = when (workspace.latestBuild.status) {
22+
WorkspaceStatus.PENDING -> QUEUED
23+
WorkspaceStatus.STARTING -> STARTING
24+
WorkspaceStatus.RUNNING -> RUNNING
25+
WorkspaceStatus.STOPPING -> STOPPING
26+
WorkspaceStatus.STOPPED -> STOPPED
27+
WorkspaceStatus.FAILED -> FAILED
28+
WorkspaceStatus.CANCELING -> CANCELING
29+
WorkspaceStatus.CANCELED -> CANCELED
30+
WorkspaceStatus.DELETING -> DELETING
31+
WorkspaceStatus.DELETED -> DELETED
3732
}
3833

3934
fun from(str: String) = WorkspaceAgentStatus.values().first { it.label.contains(str, true) }
4035
}
41-
}
36+
}

0 commit comments

Comments
 (0)