MCPcopy Create free account
hub / github.com/cli/cli / simplifyURL

Function simplifyURL

pkg/cmd/repo/clone/clone.go:265–280  ·  view source on GitHub ↗

simplifyURL strips given URL of extra parts like extra path segments (i.e., anything beyond `/owner/repo`), query strings, or fragments. This function never returns an error. The rationale behind this function is to let users clone a repo with any URL related to the repo; like: - (Tree)

(u *url.URL)

Source from the content-addressed store, hash-verified

263// - (Issue/PR comment) github.com/owner/repo/pull/999#issue-9999999999
264// - (Commit history) github.com/owner/repo/commits/main/?author=foo
265func simplifyURL(u *url.URL) *url.URL {
266 result := &url.URL{
267 Scheme: u.Scheme,
268 User: u.User,
269 Host: u.Host,
270 Path: u.Path,
271 }
272
273 pathParts := strings.SplitN(strings.Trim(u.Path, "/"), "/", 3)
274 if len(pathParts) <= 2 {
275 return result
276 }
277
278 result.Path = strings.Join(pathParts[0:2], "/")
279 return result
280}

Callers 2

cloneRunFunction · 0.85
TestSimplifyURLFunction · 0.85

Calls 1

JoinMethod · 0.80

Tested by 1

TestSimplifyURLFunction · 0.68