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

Function ParseGitHubURL

pkg/parser/github_urls.go:56–74  ·  view source on GitHub ↗

ParseGitHubURL parses a GitHub URL and extracts its components. Supports various URL formats: - GitHub Actions runs: https://github.com/owner/repo/actions/runs/12345678 - GitHub Actions runs (short): https://github.com/owner/repo/runs/12345678 - GitHub Actions job URLs: https://github.com/owner/repo

(urlStr string)

Source from the content-addressed store, hash-verified

54// - Raw content: https://raw.githubusercontent.com/owner/repo/main/path/to/file.md
55// - Enterprise URLs: https://github.example.com/owner/repo/...
56func ParseGitHubURL(urlStr string) (*GitHubURLComponents, error) {
57 urlLog.Printf("Parsing GitHub URL: %s", urlStr)
58 parsedURL, err := url.Parse(urlStr)
59 if err != nil {
60 urlLog.Printf("Failed to parse URL: %v", err)
61 return nil, fmt.Errorf("invalid URL: %w", err)
62 }
63
64 host := parsedURL.Host
65 if host == "" {
66 return nil, errors.New("URL must include a host")
67 }
68 urlLog.Printf("Detected host: %s", host)
69 if host == "raw.githubusercontent.com" {
70 urlLog.Print("Detected raw.githubusercontent.com URL")
71 return parseRawGitHubContentURL(parsedURL)
72 }
73 return parseStandardGitHubURL(parsedURL, host)
74}
75
76func parseStandardGitHubURL(parsedURL *url.URL, host string) (*GitHubURLComponents, error) {
77 pathParts := strings.Split(strings.Trim(parsedURL.Path, "/"), "/")

Callers 10

ParseRunURLExtendedFunction · 0.85
ParsePRURLFunction · 0.85
ParseRepoFileURLFunction · 0.85
TestParseRunURLFunction · 0.85

Calls 5

parseRawGitHubContentURLFunction · 0.85
parseStandardGitHubURLFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 7

TestParseRunURLFunction · 0.68