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

Function ParseURL

pkg/cmd/pr/shared/finder.go:304–327  ·  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

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

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