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)
| 54 | // - Raw content: https://raw.githubusercontent.com/owner/repo/main/path/to/file.md |
| 55 | // - Enterprise URLs: https://github.example.com/owner/repo/... |
| 56 | func 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 | |
| 76 | func parseStandardGitHubURL(parsedURL *url.URL, host string) (*GitHubURLComponents, error) { |
| 77 | pathParts := strings.Split(strings.Trim(parsedURL.Path, "/"), "/") |