summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2019-05-04 15:39:03 +0300
committerGitHub <noreply@github.com>2019-05-04 15:39:03 +0300
commit1fa96629461ac4229932b0a4526fc2f60c88ec51 (patch)
treecaa3906758c6998bb6450932393336ac57c3db19 /routers
parent2933ae4e88bb954af76c4e1e67c7ab1e4892e4a4 (diff)
downloadgitea-1fa96629461ac4229932b0a4526fc2f60c88ec51.tar.gz
gitea-1fa96629461ac4229932b0a4526fc2f60c88ec51.zip
Git statistics in Activity tab (#4724)
* Initial implementation for git statistics in Activity tab * Create top user by commit count endpoint * Add UI and update src-d/go-git dependency * Add coloring * Fix typo * Move git activity stats data extraction to git module * Fix message * Add git code stats test
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/activity.go33
-rw-r--r--routers/routes/routes.go5
2 files changed, 36 insertions, 2 deletions
diff --git a/routers/repo/activity.go b/routers/repo/activity.go
index 5d90d73506..e170a91299 100644
--- a/routers/repo/activity.go
+++ b/routers/repo/activity.go
@@ -44,13 +44,42 @@ func Activity(ctx *context.Context) {
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
var err error
- if ctx.Data["Activity"], err = models.GetActivityStats(ctx.Repo.Repository.ID, timeFrom,
+ if ctx.Data["Activity"], err = models.GetActivityStats(ctx.Repo.Repository, timeFrom,
ctx.Repo.CanRead(models.UnitTypeReleases),
ctx.Repo.CanRead(models.UnitTypeIssues),
- ctx.Repo.CanRead(models.UnitTypePullRequests)); err != nil {
+ ctx.Repo.CanRead(models.UnitTypePullRequests),
+ ctx.Repo.CanRead(models.UnitTypeCode)); err != nil {
ctx.ServerError("GetActivityStats", err)
return
}
ctx.HTML(200, tplActivity)
}
+
+// ActivityAuthors renders JSON with top commit authors for given time period over all branches
+func ActivityAuthors(ctx *context.Context) {
+ timeUntil := time.Now()
+ var timeFrom time.Time
+
+ switch ctx.Params("period") {
+ case "daily":
+ timeFrom = timeUntil.Add(-time.Hour * 24)
+ case "halfweekly":
+ timeFrom = timeUntil.Add(-time.Hour * 72)
+ case "weekly":
+ timeFrom = timeUntil.Add(-time.Hour * 168)
+ case "monthly":
+ timeFrom = timeUntil.AddDate(0, -1, 0)
+ default:
+ timeFrom = timeUntil.Add(-time.Hour * 168)
+ }
+
+ var err error
+ authors, err := models.GetActivityStatsTopAuthors(ctx.Repo.Repository, timeFrom, 10)
+ if err != nil {
+ ctx.ServerError("GetActivityStatsTopAuthors", err)
+ return
+ }
+
+ ctx.JSON(200, authors)
+}
diff --git a/routers/routes/routes.go b/routers/routes/routes.go
index 5fa37a8417..938afcab79 100644
--- a/routers/routes/routes.go
+++ b/routers/routes/routes.go
@@ -802,6 +802,11 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/:period", repo.Activity)
}, context.RepoRef(), repo.MustBeNotEmpty, context.RequireRepoReaderOr(models.UnitTypePullRequests, models.UnitTypeIssues, models.UnitTypeReleases))
+ m.Group("/activity_author_data", func() {
+ m.Get("", repo.ActivityAuthors)
+ m.Get("/:period", repo.ActivityAuthors)
+ }, context.RepoRef(), repo.MustBeNotEmpty, context.RequireRepoReaderOr(models.UnitTypeCode))
+
m.Get("/archive/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.Download)
m.Group("/branches", func() {