ParsePRURL is a convenience function that parses a GitHub PR URL and extracts PR information. Expected format: https://github.com/owner/repo/pull/123 or https://github.enterprise.com/owner/repo/pull/123
(prURL string)
| 311 | // ParsePRURL is a convenience function that parses a GitHub PR URL and extracts PR information. |
| 312 | // Expected format: https://github.com/owner/repo/pull/123 or https://github.enterprise.com/owner/repo/pull/123 |
| 313 | func ParsePRURL(prURL string) (owner, repo string, prNumber int, err error) { |
| 314 | components, err := ParseGitHubURL(prURL) |
| 315 | if err != nil { |
| 316 | return "", "", 0, err |
| 317 | } |
| 318 | |
| 319 | if components.Type != URLTypePullRequest { |
| 320 | return "", "", 0, errors.New("URL is not a GitHub PR URL") |
| 321 | } |
| 322 | |
| 323 | // Validate that Number fits in int range (important for 32-bit systems) |
| 324 | // Note: PR numbers are parsed with ParseInt(..., 10, 32) so they should always fit |
| 325 | const maxInt = int(^uint(0) >> 1) |
| 326 | const minInt = -maxInt - 1 |
| 327 | if components.Number > int64(maxInt) || components.Number < int64(minInt) { |
| 328 | return "", "", 0, fmt.Errorf("PR number %d is out of range for int type", components.Number) |
| 329 | } |
| 330 | |
| 331 | return components.Owner, components.Repo, int(components.Number), nil |
| 332 | } |
| 333 | |
| 334 | // ParseRepoFileURL is a convenience function that parses a GitHub repository file URL. |
| 335 | // It accepts URLs like: |