Browse Source

Merge pull request '开发年龄统计指标合入' (#504) from fix-333 into V20211018

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/504
Reviewed-by: lewis <747342561@qq.com>
pull/505/head
lewis 3 years ago
parent
commit
bd3d9ad3fb
1 changed files with 26 additions and 0 deletions
  1. +26
    -0
      modules/git/repo_stats_custom.go

+ 26
- 0
modules/git/repo_stats_custom.go View File

@@ -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()


Loading…
Cancel
Save