MCPcopy Create free account
hub / github.com/cli/cli / contentsAPIPath

Function contentsAPIPath

pkg/cmd/repo/read-file/http.go:202–213  ·  view source on GitHub ↗

contentsAPIPath builds the absolute Contents API URL for a path and optional ref.

(repo ghrepo.Interface, filePath, ref string)

Source from the content-addressed store, hash-verified

200
201// contentsAPIPath builds the absolute Contents API URL for a path and optional ref.
202func contentsAPIPath(repo ghrepo.Interface, filePath, ref string) (safeurl.SafeURL, error) {
203 // The Contents API accepts a fully percent-encoded path, including path separators
204 // encoded as %2F, so spaces and other special characters are handled transparently.
205 u, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "contents", strings.TrimPrefix(filePath, "/"))
206 if err != nil {
207 return nil, err
208 }
209 if ref != "" {
210 u.SetQuery("ref", ref)
211 }
212 return u, nil
213}

Callers 3

fetchContentFunction · 0.85
fetchRawFileFunction · 0.85
Test_contentsAPIPathFunction · 0.85

Calls 6

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
SetQueryMethod · 0.80
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65

Tested by 1

Test_contentsAPIPathFunction · 0.68