MCPcopy Create free account
hub / github.com/github/gh-aw / ParsePRURL

Function ParsePRURL

pkg/parser/github_urls.go:313–332  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
313func 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:

Callers 3

transferPRFunction · 0.92
TestParsePRURLFunction · 0.92
TestParsePRURLFunction · 0.85

Calls 2

ParseGitHubURLFunction · 0.85
ErrorfMethod · 0.45

Tested by 2

TestParsePRURLFunction · 0.74
TestParsePRURLFunction · 0.68