|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package repo
-
- import (
- "fmt"
- "net/http"
- "time"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/git"
- "code.gitea.io/gitea/modules/log"
- )
-
- func QueryUserStaticData(ctx *context.Context) {
- startDate := ctx.Query("startDate")
- endDate := ctx.Query("endDate")
- log.Info("startDate=" + startDate + " endDate=" + endDate)
- startTime, _ := time.Parse("2006-01-02", startDate)
- endTime, _ := time.Parse("2006-01-02", endDate)
- log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix()))
- ctx.JSON(http.StatusOK, models.QueryUserStaticData(startTime.Unix(), endTime.Unix()))
-
- }
-
- 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)
- }
|