Skip to content

Commit ba898b9

Browse files
committed
rm copypasta
1 parent 9127d62 commit ba898b9

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

mcp/tools/tools_coder.go

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,9 @@ func handleCoderWorkspaceExec(client *codersdk.Client) mcpserver.ToolHandlerFunc
214214

215215
// Attempt to fetch the workspace. We may get a UUID or a name, so try to
216216
// handle both.
217-
var ws codersdk.Workspace
218-
if wsid, err := uuid.Parse(wsArg); err == nil {
219-
ws, err = client.Workspace(ctx, wsid)
220-
if err != nil {
221-
return nil, xerrors.Errorf("failed to fetch workspace: %w", err)
222-
}
223-
} else {
224-
owner, workspaceName, err := splitNamedWorkspace(wsArg)
225-
if err != nil {
226-
return nil, xerrors.Errorf("failed to split workspace name: %w", err)
227-
}
228-
ws, err = client.WorkspaceByOwnerAndName(ctx, owner, workspaceName, codersdk.WorkspaceOptions{})
229-
if err != nil {
230-
return nil, xerrors.Errorf("failed to fetch workspace: %w", err)
231-
}
217+
ws, err := getWorkspaceByIDOrOwnerName(ctx, client, wsArg)
218+
if err != nil {
219+
return nil, xerrors.Errorf("failed to fetch workspace: %w", err)
232220
}
233221

234222
// Ensure the workspace is started.
@@ -277,19 +265,9 @@ func handleCoderWorkspaceExec(client *codersdk.Client) mcpserver.ToolHandlerFunc
277265
}
278266
}
279267

280-
// COPYPASTA: from cli/root.go
281-
func splitNamedWorkspace(identifier string) (owner string, workspaceName string, err error) {
282-
parts := strings.Split(identifier, "/")
283-
284-
switch len(parts) {
285-
case 1:
286-
owner = codersdk.Me
287-
workspaceName = parts[0]
288-
case 2:
289-
owner = parts[0]
290-
workspaceName = parts[1]
291-
default:
292-
return "", "", xerrors.Errorf("invalid workspace name: %q should be in the format <workspace> or <owner>/<workspace>", identifier)
268+
func getWorkspaceByIDOrOwnerName(ctx context.Context, client *codersdk.Client, identifier string) (codersdk.Workspace, error) {
269+
if wsid, err := uuid.Parse(identifier); err == nil {
270+
return client.Workspace(ctx, wsid)
293271
}
294-
return owner, workspaceName, nil
272+
return client.WorkspaceByOwnerAndName(ctx, codersdk.Me, identifier, codersdk.WorkspaceOptions{})
295273
}

0 commit comments

Comments
 (0)