package repo import ( "time" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" ) func TimingCountDataByDate(date string) { t, _ := time.Parse("2006-01-02", date) startTime := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) endTime := time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, t.Location()) //query wiki data log.Info("start to time count data") wikiMap := make(map[string]int) repoList, err := models.GetAllRepositories() if err != nil { log.Error("query repo error.") return } log.Info("start to query wiki data") for _, repoRecord := range repoList { wikiPath := models.WikiPath(repoRecord.OwnerName, repoRecord.Name) time, err := git.GetLatestCommitTime(wikiPath) if err == nil { log.Info("last commit time:" + time.Format("2006-01-02 15:04:05") + " wikiPath=" + wikiPath) if time.After(startTime) { wikiRepo, _, err := FindWikiRepoCommitByWikiPath(wikiPath) if err != nil { log.Error("wiki not exist. wikiPath=" + wikiPath) } else { log.Info("wiki exist, wikiPath=" + wikiPath) list, err := wikiRepo.GetCommitByPathAndDays(wikiPath, 1) if err != nil { log.Info("err,err=v%", err) } else { for logEntry := list.Front(); logEntry != nil; logEntry = logEntry.Next() { commit := logEntry.Value.(*git.Commit) log.Info("commit msg=" + commit.CommitMessage + " time=" + commit.Committer.When.Format("2006-01-02 15:04:05") + " user=" + commit.Committer.Name) if _, ok := wikiMap[commit.Committer.Name]; !ok { wikiMap[commit.Committer.Name] = 1 } else { wikiMap[commit.Committer.Name] += 1 } } } } } } } //other user info data models.CounDataByDate(wikiMap, startTime, endTime) } func TimingCountData() { log.Info("start to time count data") currentTimeNow := time.Now() log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) startTime := currentTimeNow.AddDate(0, 0, -1).Format("2006-01-02") TimingCountDataByDate(startTime) }