mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-21 14:32:03 +00:00
Fix how to construct URLs for finding all the commits related to a
github file The existing logic sets the creation time of a github file to the time when the github repository was created. The fix sets the creation time of a github file to the time when the file was created.
This commit is contained in:
@@ -116,9 +116,11 @@ type RequestConfig struct {
|
||||
// the URL method to get the string value of the URL. See request.CopyWith, to
|
||||
// understand why the request object is useful.
|
||||
func (rc RequestConfig) CodeSearchRequestWith(query Query) request {
|
||||
req := rc.makeRequest("search/code", query)
|
||||
req.vals.Set("sort", "indexed")
|
||||
req.vals.Set("order", "desc")
|
||||
vals := url.Values{
|
||||
"sort": []string{"indexed"},
|
||||
"order": []string{"desc"},
|
||||
}
|
||||
req := rc.makeRequest("search/code", query, vals)
|
||||
return req
|
||||
}
|
||||
|
||||
@@ -126,27 +128,25 @@ func (rc RequestConfig) CodeSearchRequestWith(query Query) request {
|
||||
// query for the Github API to find the dowload information of this filepath.
|
||||
func (rc RequestConfig) ContentsRequest(fullRepoName, path string) string {
|
||||
uri := fmt.Sprintf("repos/%s/contents/%s", fullRepoName, path)
|
||||
return rc.makeRequest(uri, Query{}).URL()
|
||||
return rc.makeRequest(uri, Query{}, url.Values{}).URL()
|
||||
}
|
||||
|
||||
func (rc RequestConfig) ReposRequest(fullRepoName string) string {
|
||||
uri := fmt.Sprintf("repos/%s", fullRepoName)
|
||||
return rc.makeRequest(uri, Query{}).URL()
|
||||
}
|
||||
|
||||
func escapeSpace(s string) string {
|
||||
return strings.Replace(s, " ", "%20", -1)
|
||||
return rc.makeRequest(uri, Query{}, url.Values{}).URL()
|
||||
}
|
||||
|
||||
// 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(escapeSpace(path))}).URL()
|
||||
vals := url.Values{
|
||||
"path": []string{path},
|
||||
}
|
||||
return rc.makeRequest(uri, Query{}, vals).URL()
|
||||
}
|
||||
|
||||
func (rc RequestConfig) makeRequest(path string, query Query) request {
|
||||
vals := url.Values{}
|
||||
func (rc RequestConfig) makeRequest(path string, query Query, vals url.Values) request {
|
||||
vals.Set(perPageArg, fmt.Sprint(rc.perPage))
|
||||
|
||||
return request{
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestGithubSearchQuery(t *testing.T) {
|
||||
"examples/helloWorld/kustomization.yaml?per_page=100",
|
||||
|
||||
expectedCommitsQuery: "https://api.github.com/repos/kubernetes-sigs/kustomize/commits?" +
|
||||
"q=path:examples/helloWorld/kustomization.yaml&per_page=100",
|
||||
"path=examples%2FhelloWorld%2Fkustomization.yaml&per_page=100",
|
||||
},
|
||||
{
|
||||
rc: RequestConfig{
|
||||
@@ -121,7 +121,7 @@ func TestGithubSearchQuery(t *testing.T) {
|
||||
"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",
|
||||
"path=examples+1%2FhelloWorld%2Fkustomization.yaml&per_page=100",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user