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