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)
| 32 | // diverges from the go-git URL parser. To ensure consistency, we now |
| 33 | // use go-git directly. |
| 34 | func 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 | } |
no outgoing calls
no test coverage detected