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

Function ParseRepoURL

internal/ebutil/giturls.go:34–57  ·  view source on GitHub ↗

ParseRepoURL parses the given repository URL into its components. We used to use chainguard-dev/git-urls for this, but its behaviour diverges from the go-git URL parser. To ensure consistency, we now use go-git directly.

(repoURL string)

Source from the content-addressed store, hash-verified

32// diverges from the go-git URL parser. To ensure consistency, we now
33// use go-git directly.
34func ParseRepoURL(repoURL string) (*ParsedURL, error) {
35 // Trim leading and trailing whitespace
36 repoURL = strings.TrimSpace(repoURL)
37 // Trim #reference from path
38 var reference string
39 if idx := strings.Index(repoURL, "#"); idx > -1 {
40 reference = repoURL[idx+1:]
41 repoURL = repoURL[:idx]
42 }
43 parsed, err := gittransport.NewEndpoint(repoURL)
44 if err != nil {
45 return nil, &InvalidRepoURLError{repoURL: repoURL, inner: err}
46 }
47 return &ParsedURL{
48 Protocol: parsed.Protocol,
49 User: parsed.User,
50 Password: parsed.Password,
51 Host: parsed.Host,
52 Port: parsed.Port,
53 Path: parsed.Path,
54 Reference: reference,
55 Cleaned: repoURL,
56 }, nil
57}

Callers 3

CloneRepoFunction · 0.92
SetupRepoAuthFunction · 0.92
DefaultWorkspaceFolderFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected