Skip to content

Commit f86a119

Browse files
committed
chore: move getServerURL under Deps
1 parent ec57659 commit f86a119

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

codersdk/toolsdk/chatgpt.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ import (
1414
"github.com/coder/coder/v2/codersdk"
1515
)
1616

17-
func getServerURL(deps Deps) string {
18-
serverURLCopy := *deps.coderClient.URL
19-
serverURLCopy.Path = ""
20-
serverURLCopy.RawQuery = ""
21-
return serverURLCopy.String()
22-
}
23-
2417
type ObjectType string
2518

2619
const (
@@ -56,7 +49,7 @@ func createObjectID(objectType ObjectType, id string) ObjectID {
5649
}
5750

5851
func searchTemplates(ctx context.Context, deps Deps, query string) ([]SearchResultItem, error) {
59-
serverURL := getServerURL(deps)
52+
serverURL := deps.getServerURL()
6053
templates, err := deps.coderClient.Templates(ctx, codersdk.TemplateFilter{
6154
SearchQuery: query,
6255
})
@@ -76,7 +69,7 @@ func searchTemplates(ctx context.Context, deps Deps, query string) ([]SearchResu
7669
}
7770

7871
func searchWorkspaces(ctx context.Context, deps Deps, query string) ([]SearchResultItem, error) {
79-
serverURL := getServerURL(deps)
72+
serverURL := deps.getServerURL()
8073
workspaces, err := deps.coderClient.Workspaces(ctx, codersdk.WorkspaceFilter{
8174
FilterQuery: query,
8275
})
@@ -351,7 +344,7 @@ func fetchWorkspace(ctx context.Context, deps Deps, workspaceID string) (FetchRe
351344
ID: workspace.ID.String(),
352345
Title: workspace.Name,
353346
Text: string(workspaceJSON),
354-
URL: fmt.Sprintf("%s/%s/%s", getServerURL(deps), workspace.OwnerName, workspace.Name),
347+
URL: fmt.Sprintf("%s/%s/%s", deps.getServerURL(), workspace.OwnerName, workspace.Name),
355348
}, nil
356349
}
357350

@@ -372,7 +365,7 @@ func fetchTemplate(ctx context.Context, deps Deps, templateID string) (FetchResu
372365
ID: template.ID.String(),
373366
Title: template.DisplayName,
374367
Text: string(templateJSON),
375-
URL: fmt.Sprintf("%s/templates/%s/%s", getServerURL(deps), template.OrganizationName, template.Name),
368+
URL: fmt.Sprintf("%s/templates/%s/%s", deps.getServerURL(), template.OrganizationName, template.Name),
376369
}, nil
377370
}
378371

codersdk/toolsdk/toolsdk.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ type Deps struct {
5858
report func(ReportTaskArgs) error
5959
}
6060

61+
func (d Deps) getServerURL() string {
62+
serverURLCopy := *d.coderClient.URL
63+
serverURLCopy.Path = ""
64+
serverURLCopy.RawQuery = ""
65+
return serverURLCopy.String()
66+
}
67+
6168
func WithTaskReporter(fn func(ReportTaskArgs) error) func(*Deps) {
6269
return func(d *Deps) {
6370
d.report = fn

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy