mirror of
https://github.com/avelino/awesome-go.git
synced 2025-01-31 04:48:53 +00:00
refactor testCommitAge
This commit is contained in:
parent
8bac0087c0
commit
c969fe29c4
@ -214,9 +214,9 @@ func getRepoStates(toRun bool, href string, client *http.Client) ([]string, bool
|
|||||||
return staleRepos, isRepoAdded
|
return staleRepos, isRepoAdded
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCommitAge(toRun bool, href string, client *http.Client, staleRepos *[]string) bool {
|
func checkRepoCommitActivity(toRun bool, href string, client *http.Client) ([]string, bool) {
|
||||||
if !toRun {
|
if !toRun {
|
||||||
return false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
ownerRepo := strings.ReplaceAll(href, "https://github.com", "")
|
ownerRepo := strings.ReplaceAll(href, "https://github.com", "")
|
||||||
@ -224,7 +224,7 @@ func testCommitAge(toRun bool, href string, client *http.Client, staleRepos *[]s
|
|||||||
req, err := http.NewRequest("GET", apiCall, nil)
|
req, err := http.NewRequest("GET", apiCall, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed at repository %s\n", href)
|
log.Printf("Failed at repository %s\n", href)
|
||||||
return false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
since := timeNow.Add(-1 * 365 * 24 * numberOfYears * time.Hour)
|
since := timeNow.Add(-1 * 365 * 24 * numberOfYears * time.Hour)
|
||||||
@ -237,23 +237,26 @@ func testCommitAge(toRun bool, href string, client *http.Client, staleRepos *[]s
|
|||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed at repository %s\n", href)
|
log.Printf("Failed at repository %s\n", href)
|
||||||
return false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
var respObj []map[string]interface{}
|
var respObj []map[string]interface{}
|
||||||
|
// FIXME: handle error in all that cases
|
||||||
json.NewDecoder(resp.Body).Decode(&respObj)
|
json.NewDecoder(resp.Body).Decode(&respObj)
|
||||||
|
|
||||||
isRepoAdded := false
|
var warnings []string
|
||||||
|
var isRepoAdded bool
|
||||||
isAged := len(respObj) == 0
|
isAged := len(respObj) == 0
|
||||||
if isAged {
|
if isAged {
|
||||||
log.Printf("%s has not had a commit in a while", href)
|
log.Printf("%s has not had a commit in a while", href)
|
||||||
*staleRepos = append(*staleRepos, href)
|
warnings = append(warnings, href)
|
||||||
isRepoAdded = true
|
isRepoAdded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return isRepoAdded
|
// FIXME: expression `(len(warnings) > 0) == isRepoAdded` is always true.
|
||||||
|
return warnings, isRepoAdded
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStaleRepository(t *testing.T) {
|
func TestStaleRepository(t *testing.T) {
|
||||||
@ -306,7 +309,9 @@ func TestStaleRepository(t *testing.T) {
|
|||||||
staleRepos2, isRepoAdded := getRepoStates(true, href, client)
|
staleRepos2, isRepoAdded := getRepoStates(true, href, client)
|
||||||
staleRepos = append(staleRepos, staleRepos2...)
|
staleRepos = append(staleRepos, staleRepos2...)
|
||||||
|
|
||||||
isRepoAdded = testCommitAge(!isRepoAdded, href, client, &staleRepos)
|
staleRepos2, isRepoAdded = checkRepoCommitActivity(!isRepoAdded, href, client)
|
||||||
|
staleRepos = append(staleRepos, staleRepos2...)
|
||||||
|
|
||||||
if isRepoAdded {
|
if isRepoAdded {
|
||||||
ctr++
|
ctr++
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user