Skip to content

Commit 478a5b1

Browse files
authored
feat: set 'jetbrains_connection' as build reason on workspace start (#150)
This PR is part of coder/coder#18827 which introduces new build reason values to identify what type of connection triggered a workspace build, helping to troubleshoot workspace-related issues.
1 parent a9c5eb3 commit 478a5b1

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/main/kotlin/com/coder/toolbox/sdk/CoderRestClient.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.coder.toolbox.sdk.v2.models.User
1515
import com.coder.toolbox.sdk.v2.models.Workspace
1616
import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
1717
import com.coder.toolbox.sdk.v2.models.WorkspaceBuild
18+
import com.coder.toolbox.sdk.v2.models.WorkspaceBuildReason
1819
import com.coder.toolbox.sdk.v2.models.WorkspaceResource
1920
import com.coder.toolbox.sdk.v2.models.WorkspaceStatus
2021
import com.coder.toolbox.sdk.v2.models.WorkspaceTransition
@@ -271,7 +272,12 @@ open class CoderRestClient(
271272
* @throws [APIResponseException].
272273
*/
273274
suspend fun startWorkspace(workspace: Workspace): WorkspaceBuild {
274-
val buildRequest = CreateWorkspaceBuildRequest(null, WorkspaceTransition.START)
275+
val buildRequest = CreateWorkspaceBuildRequest(
276+
null,
277+
WorkspaceTransition.START,
278+
null,
279+
WorkspaceBuildReason.JETBRAINS_CONNECTION
280+
)
275281
val buildResponse = retroRestClient.createWorkspaceBuild(workspace.id, buildRequest)
276282
if (buildResponse.code() != HttpURLConnection.HTTP_CREATED) {
277283
throw APIResponseException(

src/main/kotlin/com/coder/toolbox/sdk/v2/models/CreateWorkspaceBuildRequest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ data class CreateWorkspaceBuildRequest(
1010
@Json(name = "template_version_id") val templateVersionID: UUID?,
1111
// Use to start, stop and delete the workspace.
1212
@Json(name = "transition") val transition: WorkspaceTransition,
13-
@Json(name = "orphan") var orphan: Boolean? = null
13+
@Json(name = "orphan") var orphan: Boolean? = null,
14+
@Json(name = "reason") var reason: WorkspaceBuildReason? = null
1415
) {
1516
override fun equals(other: Any?): Boolean {
1617
if (this === other) return true
@@ -21,13 +22,15 @@ data class CreateWorkspaceBuildRequest(
2122
if (templateVersionID != other.templateVersionID) return false
2223
if (transition != other.transition) return false
2324
if (orphan != other.orphan) return false
25+
if (reason != other.reason) return false
2426
return true
2527
}
2628

2729
override fun hashCode(): Int {
2830
var result = orphan?.hashCode() ?: 0
2931
result = 31 * result + (templateVersionID?.hashCode() ?: 0)
3032
result = 31 * result + transition.hashCode()
33+
result = 31 * result + (reason?.hashCode() ?: 0)
3134
return result
3235
}
3336
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.coder.toolbox.sdk.v2.models
2+
3+
import com.squareup.moshi.Json
4+
5+
enum class WorkspaceBuildReason {
6+
@Json(name = "jetbrains_connection") JETBRAINS_CONNECTION,
7+
}

0 commit comments

Comments
 (0)