Skip to content

Commit b54b74a

Browse files
committed
impl: prefer agent name over agent id in URI handler
Agent name is easier to resolve in jetbrains gateway module
1 parent 546d317 commit b54b74a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/main/kotlin/com/coder/gateway/util/LinkHandler.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,16 @@ internal fun getMatchingAgent(
327327
}
328328

329329
// If the agent is missing and the workspace has only one, use that.
330-
// Prefer the ID over the name if both are set.
331-
val agent =
332-
if (!parameters.agentID().isNullOrBlank()) {
333-
agents.firstOrNull { it.id.toString() == parameters.agentID() }
334-
} else if (!parameters.agentName().isNullOrBlank()) {
335-
agents.firstOrNull { it.name == parameters.agentName() }
336-
} else if (agents.size == 1) {
337-
agents.first()
338-
} else {
339-
null
340-
}
330+
// Prefer the name over the id if both are set.
331+
val agent = if (!parameters.agentName().isNullOrBlank()) {
332+
agents.firstOrNull { it.name == parameters.agentName() }
333+
} else if (!parameters.agentID().isNullOrBlank()) {
334+
agents.firstOrNull { it.id.toString() == parameters.agentID() }
335+
} else if (agents.size == 1) {
336+
agents.first()
337+
} else {
338+
null
339+
}
341340

342341
if (agent == null) {
343342
if (!parameters.agentID().isNullOrBlank()) {

src/main/kotlin/com/coder/gateway/util/LinkMap.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ fun Map<String, String>.owner() = this[OWNER]
2929

3030
fun Map<String, String?>.agentName() = this[AGENT_NAME]
3131

32+
@Deprecated("Use the agent name instead")
3233
fun Map<String, String?>.agentID() = this[AGENT_ID]
3334

3435
fun Map<String, String>.folder() = this[FOLDER]

0 commit comments

Comments
 (0)