contentsAPIPath builds the absolute Contents API URL for a path and optional ref.
(repo ghrepo.Interface, filePath, ref string)
| 200 | |
| 201 | // contentsAPIPath builds the absolute Contents API URL for a path and optional ref. |
| 202 | func 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 | } |