Add supports for crawling a specific git user or repo

This commit is contained in:
Haiyan Meng
2019-12-12 15:20:13 -08:00
parent 50ce2a66a3
commit a9244f759e
6 changed files with 73 additions and 36 deletions

View File

@@ -230,7 +230,6 @@ func kustomizationResultAdapter(gcl GhClient, k GhFileSpec) (
RepositoryURL: k.Repository.URL,
},
}
logger.Printf("Set the creationTime field")
creationTime, err := gcl.GetFileCreationTime(k)
if err != nil {
logger.Printf("GetFileCreationTime failed: %v", err)
@@ -533,7 +532,7 @@ func (gcl GhClient) parseGithubResponse(getRequest string) GhResponseInfo {
}
// SearchGithubAPI performs a search query and handles rate limitting for
// the 'code/search?' endpoint as well as timed retries in the case of abuse
// the 'search/code?' endpoint as well as timed retries in the case of abuse
// prevention.
func (gcl GhClient) SearchGithubAPI(query string) (*http.Response, error) {
throttleSearchAPI()

View File

@@ -90,6 +90,17 @@ func Path(p string) queryField {
return queryField{name: "path", value: p}
}
// Repo takes a repository (i.e., kubernetes-sigs/kustomize) and formats
// it according to the Github API.
func Repo(r string) queryField {
return queryField{name: "repo", value: r}
}
// Path takes a github username and formats it according to the Github API.
func User(u string) queryField {
return queryField{name: "user", value: u}
}
// RequestConfig stores common variables that must be present for the queries.
// - CodeSearchRequests: ask Github to check the code indices given a query.
// - ContentsRequests: ask Github where to download a resource given a repo and a

View File

@@ -53,8 +53,11 @@ func TestQueryType(t *testing.T) {
Filename("kustomization.yaml"),
Keyword("keyword1"),
Keyword("keyword2"),
Repo("user1/repo1"),
User("user1"),
),
expected: "q=size:24..64+filename:kustomization.yaml+keyword1+keyword2",
expected: "q=size:24..64+filename:kustomization.yaml+keyword1+keyword2+" +
"repo:user1/repo1+user:user1",
},
}

View File

@@ -243,7 +243,7 @@ func FindRangesForRepoSearch(cache cachedSearch) ([]string, error) {
if err != nil {
return nil, err
}
logger.Println("total files: ", totalFiles)
logger.Println("total kustomization files: ", totalFiles)
if githubMaxResultsPerQuery >= totalFiles {
return []string{