2017-10-14 23:17:39 +00:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2021-04-05 15:30:52 +00:00
|
|
|
"net/http"
|
2017-10-14 23:17:39 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
tplActivity base.TplName = "repo/activity"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Activity render the page to show repository latest changes
|
|
|
|
func Activity(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("repo.activity")
|
|
|
|
ctx.Data["PageIsActivity"] = true
|
|
|
|
|
|
|
|
ctx.Data["Period"] = ctx.Params("period")
|
|
|
|
|
|
|
|
timeUntil := time.Now()
|
|
|
|
var timeFrom time.Time
|
|
|
|
|
|
|
|
switch ctx.Data["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)
|
2019-11-05 05:45:48 +00:00
|
|
|
case "quarterly":
|
|
|
|
timeFrom = timeUntil.AddDate(0, -3, 0)
|
|
|
|
case "semiyearly":
|
|
|
|
timeFrom = timeUntil.AddDate(0, -6, 0)
|
|
|
|
case "yearly":
|
|
|
|
timeFrom = timeUntil.AddDate(-1, 0, 0)
|
2017-10-14 23:17:39 +00:00
|
|
|
default:
|
|
|
|
ctx.Data["Period"] = "weekly"
|
|
|
|
timeFrom = timeUntil.Add(-time.Hour * 168)
|
|
|
|
}
|
|
|
|
ctx.Data["DateFrom"] = timeFrom.Format("January 2, 2006")
|
|
|
|
ctx.Data["DateUntil"] = timeUntil.Format("January 2, 2006")
|
|
|
|
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
|
|
|
|
|
2017-10-15 21:54:53 +00:00
|
|
|
var err error
|
2019-05-04 12:39:03 +00:00
|
|
|
if ctx.Data["Activity"], err = models.GetActivityStats(ctx.Repo.Repository, timeFrom,
|
2018-11-28 11:26:14 +00:00
|
|
|
ctx.Repo.CanRead(models.UnitTypeReleases),
|
|
|
|
ctx.Repo.CanRead(models.UnitTypeIssues),
|
2019-05-04 12:39:03 +00:00
|
|
|
ctx.Repo.CanRead(models.UnitTypePullRequests),
|
|
|
|
ctx.Repo.CanRead(models.UnitTypeCode)); err != nil {
|
2018-01-10 21:34:17 +00:00
|
|
|
ctx.ServerError("GetActivityStats", err)
|
2017-10-14 23:17:39 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-10-15 02:35:26 +00:00
|
|
|
if ctx.PageData["repoActivityTopAuthors"], err = models.GetActivityStatsTopAuthors(ctx.Repo.Repository, timeFrom, 10); err != nil {
|
2020-01-20 10:07:30 +00:00
|
|
|
ctx.ServerError("GetActivityStatsTopAuthors", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.HTML(http.StatusOK, tplActivity)
|
2017-10-14 23:17:39 +00:00
|
|
|
}
|
2019-05-04 12:39:03 +00:00
|
|
|
|
|
|
|
// 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)
|
2019-11-05 05:45:48 +00:00
|
|
|
case "quarterly":
|
|
|
|
timeFrom = timeUntil.AddDate(0, -3, 0)
|
|
|
|
case "semiyearly":
|
|
|
|
timeFrom = timeUntil.AddDate(0, -6, 0)
|
|
|
|
case "yearly":
|
|
|
|
timeFrom = timeUntil.AddDate(-1, 0, 0)
|
2019-05-04 12:39:03 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.JSON(http.StatusOK, authors)
|
2019-05-04 12:39:03 +00:00
|
|
|
}
|