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)
| 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. |
| 304 | func 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 | |
| 329 | var fullReferenceRE = regexp.MustCompile(`^(?:([^/]+)/([^/]+))#(\d+)$`) |
| 330 |