Escape spaces in the query paths of git commit requests

This commit is contained in:
Haiyan Meng
2019-12-12 09:42:32 -08:00
parent 57059b74f5
commit d9239104aa
2 changed files with 25 additions and 1 deletions

View File

@@ -123,11 +123,15 @@ func (rc RequestConfig) ReposRequest(fullRepoName string) string {
return rc.makeRequest(uri, Query{}).URL()
}
func escapeSpace(s string) string {
return strings.Replace(s, " ", "%20", -1)
}
// CommitsRequest given the repo name, and a filepath returns a formatted query
// for the Github API to find the commits that affect this file.
func (rc RequestConfig) CommitsRequest(fullRepoName, path string) string {
uri := fmt.Sprintf("repos/%s/commits", fullRepoName)
return rc.makeRequest(uri, Query{Path(path)}).URL()
return rc.makeRequest(uri, Query{Path(escapeSpace(path))}).URL()
}
func (rc RequestConfig) makeRequest(path string, query Query) request {