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

Function ParseRepoFileURL

pkg/parser/github_urls.go:340–353  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

338// - https://github.com/owner/repo/raw/main/path/to/file.md
339// - https://raw.githubusercontent.com/owner/repo/main/path/to/file.md
340func 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
355const (
356 maxGitHubOwnerIdentifierLength = 39

Callers 2

parseGitHubURLFunction · 0.92
TestParseRepoFileURLFunction · 0.85

Calls 1

ParseGitHubURLFunction · 0.85

Tested by 1

TestParseRepoFileURLFunction · 0.68