Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

impl: prefer agent name over agent id in URI handler#585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fioan89 merged 4 commits intomainfromimpl-use-agent-name-over-agent-id
Oct 1, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletionssrc/main/kotlin/com/coder/gateway/util/LinkHandler.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,7 +71,7 @@
indicator,
)

var workspace: Workspace

Check warning on line 74 in src/main/kotlin/com/coder/gateway/util/LinkHandler.kt

View workflow job for this annotation

GitHub Actions/ Qodana Community for JVM

Local 'var' is never modified and can be declared as 'val'

Variable is never modified, so it can be declared using 'val'
var workspaces: List<Workspace> = emptyList()
var workspacesAndAgents: Set<Pair<Workspace, WorkspaceAgent>> = emptySet()
if (cli.features.wildcardSSH) {
Expand DownExpand Up@@ -327,25 +327,24 @@
}

// If the agent is missing and the workspace has only one, use that.
// Prefer the ID over the name if both are set.
val agent =
if (!parameters.agentID().isNullOrBlank()) {
agents.firstOrNull { it.id.toString() == parameters.agentID() }
} else if (!parameters.agentName().isNullOrBlank()) {
agents.firstOrNull { it.name == parameters.agentName() }
} else if (agents.size == 1) {
agents.first()
} else {
null
}
// Prefer the name over the id if both are set.
val agent = if (!parameters.agentName().isNullOrBlank()) {
agents.firstOrNull { it.name == parameters.agentName() }
} else if (!parameters.agentID().isNullOrBlank()) {
agents.firstOrNull { it.id.toString() == parameters.agentID() }
} else if (agents.size == 1) {
agents.first()
} else {
null
}

if (agent == null) {
if (!parameters.agentID().isNullOrBlank()) {
throw IllegalArgumentException("The workspace \"${workspace.name}\" does not have an agent with ID \"${parameters.agentID()}\"")
} else if (!parameters.agentName().isNullOrBlank()) {
if (!parameters.agentName().isNullOrBlank()) {
throw IllegalArgumentException(
"The workspace \"${workspace.name}\"does not have an agent named \"${parameters.agentName()}\"",
"The workspace \"${workspace.name}\"does not have an agent named \"${parameters.agentName()}\"",
)
} else if (!parameters.agentID().isNullOrBlank()) {
throw IllegalArgumentException("The workspace \"${workspace.name}\" does not have an agent with ID \"${parameters.agentID()}\"")
} else {
throw MissingArgumentException(
"Unable to determine which agent to connect to; one of \"$AGENT_NAME\" or \"$AGENT_ID\" must be set because the workspace \"${workspace.name}\" has more than one agent",
Expand Down
1 change: 1 addition & 0 deletionssrc/main/kotlin/com/coder/gateway/util/LinkMap.kt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@

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

@Deprecated("Use the agent name instead")

Check notice on line 32 in src/main/kotlin/com/coder/gateway/util/LinkMap.kt

View workflow job for this annotation

GitHub Actions/ Qodana Community for JVM

@Deprecated annotation without 'replaceWith' argument

'@deprecated' annotation without a 'replaceWith' argument
fun Map<String, String?>.agentID() = this[AGENT_ID]

fun Map<String, String>.folder() = this[FOLDER]
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp