From 2856651aba473a9cdbcc16a3adfc881298bcd348 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Tue, 12 Oct 2021 09:46:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E5=B9=B4=E9=BE=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=8C=87=E6=A0=87=E5=90=88=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/git/repo_stats_custom.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/git/repo_stats_custom.go b/modules/git/repo_stats_custom.go index 95f1086ad..50a740fb0 100644 --- a/modules/git/repo_stats_custom.go +++ b/modules/git/repo_stats_custom.go @@ -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()