|
|
@@ -13,6 +13,7 @@ import ( |
|
|
|
type RepoKPIStats struct { |
|
|
|
Contributors int64 |
|
|
|
KeyContributors int64 |
|
|
|
DevelopAge int64 |
|
|
|
ContributorsAdded int64 |
|
|
|
CommitsAdded int64 |
|
|
|
CommitLinesModified int64 |
|
|
@@ -66,6 +67,10 @@ func GetRepoKPIStats(repoPath string) (*RepoKPIStats, error) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
err = setDevelopAge(repoPath, stats) |
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("FillFromGit: %v", err) |
|
|
|
} |
|
|
|
err = setRepoKPIStats(repoPath, fourMonthAgo, stats, newContributersDict) |
|
|
|
|
|
|
|
if err != nil { |
|
|
@@ -75,6 +80,27 @@ func GetRepoKPIStats(repoPath string) (*RepoKPIStats, error) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func setDevelopAge(repoPath string, stats *RepoKPIStats) error { |
|
|
|
args := []string{"log", "--no-merges", "--branches=*", "--format=%cd", "--date=short"} |
|
|
|
stdout, err := NewCommand(args...).RunInDirBytes(repoPath) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
scanner := bufio.NewScanner(bytes.NewReader(stdout)) |
|
|
|
scanner.Split(bufio.ScanLines) |
|
|
|
developMonth := make(map[string]struct{}) |
|
|
|
for scanner.Scan() { |
|
|
|
l := strings.TrimSpace(scanner.Text()) |
|
|
|
month := l[0:strings.LastIndex(l, "-")] |
|
|
|
if _, ok := developMonth[month]; !ok { |
|
|
|
developMonth[month] = struct{}{} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
stats.DevelopAge = int64(len(developMonth)) |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
//获取一天内的用户贡献指标 |
|
|
|
func GetUserKPIStats(repoPath string) (map[string]*UserKPIStats, error) { |
|
|
|
timeUntil := time.Now() |
|
|
|