MCPcopy
hub / github.com/cli/cli / ParseURL

Function ParseURL

pkg/cmd/pr/shared/finder.go:306–329  ·  view source on GitHub ↗

ParseURL parses a pull request URL and returns the repository, pull request number, and any tailing path components. If there is no error, the returned repo is not nil and will have non-empty hostname.

(prURL string)

Source from the content-addressed store, hash-verified

304// number, and any tailing path components. If there is no error, the returned
305// repo is not nil and will have non-empty hostname.
306func ParseURL(prURL string) (ghrepo.Interface, int, string, error) {
307 if prURL == "" {
308 return nil, 0, "", fmt.Errorf("invalid URL: %q", prURL)
309 }
310
311 u, err := url.Parse(prURL)
312 if err != nil {
313 return nil, 0, "", err
314 }
315
316 if u.Scheme != "https" && u.Scheme != "http" {
317 return nil, 0, "", fmt.Errorf("invalid scheme: %s", u.Scheme)
318 }
319
320 m := pullURLRE.FindStringSubmatch(u.Path)
321 if m == nil {
322 return nil, 0, "", fmt.Errorf("not a pull request URL: %s", prURL)
323 }
324
325 repo := ghrepo.NewWithHost(m[1], m[2], u.Hostname())
326 prNumber, _ := strconv.Atoi(m[3])
327 tail := m[4]
328 return repo, prNumber, tail, nil
329}
330
331var fullReferenceRE = regexp.MustCompile(`^(?:([^/]+)/([^/]+))#(\d+)$`)
332

Callers 3

NewCmdEditFunction · 0.92
FindMethod · 0.70
TestParseURLFunction · 0.70

Calls 2

NewWithHostFunction · 0.92
ErrorfMethod · 0.65

Tested by 1

TestParseURLFunction · 0.56