in cmd/validate-rules/staging/github_utils.go [35:82]
func fetchKubernetesStagingDirectoryFiles(branch string) ([]File, error) {
url := "https://api.github.com/repos/kubernetes/kubernetes/contents/staging/src/k8s.io?ref=" + branch
spaceClient := http.Client{}
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
var res *http.Response
count := 0
for {
res, err = spaceClient.Do(req)
if err != nil {
return nil, err
}
if res.Body != nil {
defer res.Body.Close()
}
if res.StatusCode == http.StatusForbidden {
// try after some time as we hit GH API limit
time.Sleep(5 * time.Second)
count++
} else {
// try for 10 mins then give up!
if count == 120 {
return nil, fmt.Errorf("hitting github API limits, bailing out")
}
break
}
}
body, readErr := ioutil.ReadAll(res.Body)
if readErr != nil {
return nil, readErr
}
var result []File
jsonErr := json.Unmarshal(body, &result)
if jsonErr != nil {
return nil, jsonErr
}
return result, nil
}