func newChecksResp(repo string, forceRefresh bool) (checksResp, error) { if !forceRefresh { resp, err := getFromCache(repo) if err != nil { // just log the error and continue log.Println(err) } else { resp.Grade = grade(resp.Average * 100) // grade is not stored for some repos, yet return resp, nil } } // fetch the repo and grade it err := goGet(repo) if err != nil { return checksResp{}, fmt.Errorf("could not clone repo: %v", err) } dir := dirName(repo) filenames, err := check.GoFiles(dir) if err != nil { return checksResp{}, fmt.Errorf("could not get filenames: %v", err) } if len(filenames) == 0 { return checksResp{}, fmt.Errorf("no .go files found") } checks := []check.Check{ check.GoFmt{Dir: dir, Filenames: filenames}, check.GoVet{Dir: dir, Filenames: filenames}, check.GoLint{Dir: dir, Filenames: filenames}, check.GoCyclo{Dir: dir, Filenames: filenames}, check.License{Dir: dir, Filenames: []string{}}, check.Misspell{Dir: dir, Filenames: filenames}, } ch := make(chan score) for _, c := range checks { go func(c check.Check) { p, summaries, err := c.Percentage() if err != nil { log.Printf("ERROR: (%s) %v", c.Name(), err) } s := score{ Name: c.Name(), Description: c.Description(), FileSummaries: summaries, Weight: c.Weight(), Percentage: p, } ch <- s }(c) } resp := checksResp{Repo: repo, Files: len(filenames), LastRefresh: time.Now().UTC()} var total float64 var issues = make(map[string]bool) for i := 0; i < len(checks); i++ { s := <-ch resp.Checks = append(resp.Checks, s) total += s.Percentage * s.Weight for _, fs := range s.FileSummaries { issues[fs.Filename] = true } } resp.Average = total resp.Issues = len(issues) resp.Grade = grade(total * 100) return resp, nil }
func newChecksResp(repo string, forceRefresh bool) (checksResp, error) { url := repo if !strings.HasPrefix(url, "https://*****:*****@github.com/") { url = "https://*****:*****@github.com/" + url } if !forceRefresh { resp, err := getFromCache(repo) if err != nil { // just log the error and continue log.Println(err) } else { resp.Grade = grade(resp.Average * 100) // grade is not stored for some repos, yet return resp, nil } } // fetch the repo and grade it err := clone(url) if err != nil { return checksResp{}, fmt.Errorf("Could not clone repo: %v", err) } dir := dirName(url) filenames, err := check.GoFiles(dir) if err != nil { return checksResp{}, fmt.Errorf("Could not get filenames: %v", err) } if len(filenames) == 0 { return checksResp{}, fmt.Errorf("No .go files found") } checks := []check.Check{check.GoFmt{Dir: dir, Filenames: filenames}, check.GoVet{Dir: dir, Filenames: filenames}, check.GoLint{Dir: dir, Filenames: filenames}, check.GoCyclo{Dir: dir, Filenames: filenames}, } ch := make(chan score) for _, c := range checks { go func(c check.Check) { p, summaries, err := c.Percentage() if err != nil { log.Printf("ERROR: (%s) %v", c.Name(), err) } s := score{ Name: c.Name(), Description: c.Description(), FileSummaries: summaries, Percentage: p, } ch <- s }(c) } resp := checksResp{Repo: repo, Files: len(filenames), LastRefresh: time.Now().UTC()} var avg float64 var issues = make(map[string]bool) for i := 0; i < len(checks); i++ { s := <-ch resp.Checks = append(resp.Checks, s) avg += s.Percentage for _, fs := range s.FileSummaries { issues[fs.Filename] = true } } resp.Average = avg / float64(len(checks)) resp.Issues = len(issues) resp.Grade = grade(resp.Average * 100) return resp, nil }