ParseRepoFileURL is a convenience function that parses a GitHub repository file URL. It accepts URLs like: - https://github.com/owner/repo/blob/main/path/to/file.md - https://github.com/owner/repo/tree/main/path/to/dir - https://github.com/owner/repo/raw/main/path/to/file.md - https://raw.githubuser
(fileURL string)
| 338 | // - https://github.com/owner/repo/raw/main/path/to/file.md |
| 339 | // - https://raw.githubusercontent.com/owner/repo/main/path/to/file.md |
| 340 | func ParseRepoFileURL(fileURL string) (owner, repo, ref, filePath string, err error) { |
| 341 | components, err := ParseGitHubURL(fileURL) |
| 342 | if err != nil { |
| 343 | return "", "", "", "", err |
| 344 | } |
| 345 | |
| 346 | // Check if it's a file-related URL type |
| 347 | switch components.Type { |
| 348 | case URLTypeBlob, URLTypeTree, URLTypeRaw, URLTypeRawContent: |
| 349 | return components.Owner, components.Repo, components.Ref, components.Path, nil |
| 350 | default: |
| 351 | return "", "", "", "", errors.New("URL is not a GitHub file URL") |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | const ( |
| 356 | maxGitHubOwnerIdentifierLength = 39 |