diff --git a/api/internal/crawl/crawler/github/queries.go b/api/internal/crawl/crawler/github/queries.go index d49252ec9..319526daf 100644 --- a/api/internal/crawl/crawler/github/queries.go +++ b/api/internal/crawl/crawler/github/queries.go @@ -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 { diff --git a/api/internal/crawl/crawler/github/queries_test.go b/api/internal/crawl/crawler/github/queries_test.go index d09acfe6b..a5b7e820c 100644 --- a/api/internal/crawl/crawler/github/queries_test.go +++ b/api/internal/crawl/crawler/github/queries_test.go @@ -100,6 +100,26 @@ func TestGithubSearchQuery(t *testing.T) { expectedCommitsQuery: "https://api.github.com/repos/kubernetes-sigs/kustomize/commits?" + "q=path:examples/helloWorld/kustomization.yaml&per_page=100", }, + { + rc: RequestConfig{ + perPage: perPage, + }, + codeQuery: Query{ + Filename("kustomization.yaml"), + Filesize(RangeWithin{64, 128}), + }, + fullRepoName: "kubernetes-sigs/kustomize", + path: "examples 1/helloWorld/kustomization.yaml", + + expectedCodeQuery: "https://api.github.com/search/code?" + + "q=filename:kustomization.yaml+size:64..128&order=desc&per_page=100&sort=indexed", + + expectedContentsQuery: "https://api.github.com/repos/kubernetes-sigs/kustomize/contents/" + + "examples%201/helloWorld/kustomization.yaml?per_page=100", + + expectedCommitsQuery: "https://api.github.com/repos/kubernetes-sigs/kustomize/commits?" + + "q=path:examples%201/helloWorld/kustomization.yaml&per_page=100", + }, } for _, test := range testCases {