MCPcopy Create free account
hub / github.com/coder/envbuilder / DefaultWorkspaceFolder

Function DefaultWorkspaceFolder

options/defaults.go:17–38  ·  view source on GitHub ↗

DefaultWorkspaceFolder returns the default workspace folder for a given repository URL.

(workspacesFolder, repoURL string)

Source from the content-addressed store, hash-verified

15// DefaultWorkspaceFolder returns the default workspace folder
16// for a given repository URL.
17func DefaultWorkspaceFolder(workspacesFolder, repoURL string) string {
18 // emptyWorkspaceDir is the path to a workspace that has
19 // nothing going on... it's empty!
20 emptyWorkspaceDir := workspacesFolder + "/empty"
21
22 if repoURL == "" {
23 return emptyWorkspaceDir
24 }
25 parsed, err := ebutil.ParseRepoURL(repoURL)
26 if err != nil {
27 return emptyWorkspaceDir
28 }
29 repo := path.Base(parsed.Path)
30 // Giturls parsing never actually fails since ParseLocal never
31 // errors and places the entire URL in the Path field. This check
32 // ensures it's at least a Unix path containing forwardslash.
33 if repo == repoURL || repo == "/" || repo == "." || repo == "" {
34 return emptyWorkspaceDir
35 }
36 repo = strings.TrimSuffix(repo, ".git")
37 return fmt.Sprintf("%s/%s", workspacesFolder, repo)
38}
39
40func (o *Options) SetDefaults() {
41 // Temporarily removed these from the default settings to prevent conflicts

Callers 2

SetDefaultsMethod · 0.85

Calls 1

ParseRepoURLFunction · 0.92

Tested by 1