You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.8 KiB
104 lines
2.8 KiB
7 years ago
|
// 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 (
|
||
4 years ago
|
"net/http"
|
||
7 years ago
|
"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)
|
||
5 years ago
|
case "quarterly":
|
||
|
timeFrom = timeUntil.AddDate(0, -3, 0)
|
||
|
case "semiyearly":
|
||
|
timeFrom = timeUntil.AddDate(0, -6, 0)
|
||
|
case "yearly":
|
||
|
timeFrom = timeUntil.AddDate(-1, 0, 0)
|
||
7 years ago
|
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))
|
||
|
|
||
7 years ago
|
var err error
|
||
6 years ago
|
if ctx.Data["Activity"], err = models.GetActivityStats(ctx.Repo.Repository, timeFrom,
|
||
6 years ago
|
ctx.Repo.CanRead(models.UnitTypeReleases),
|
||
|
ctx.Repo.CanRead(models.UnitTypeIssues),
|
||
6 years ago
|
ctx.Repo.CanRead(models.UnitTypePullRequests),
|
||
|
ctx.Repo.CanRead(models.UnitTypeCode)); err != nil {
|
||
7 years ago
|
ctx.ServerError("GetActivityStats", err)
|
||
7 years ago
|
return
|
||
|
}
|
||
|
|
||
5 years ago
|
if ctx.Data["ActivityTopAuthors"], err = models.GetActivityStatsTopAuthors(ctx.Repo.Repository, timeFrom, 10); err != nil {
|
||
|
ctx.ServerError("GetActivityStatsTopAuthors", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
4 years ago
|
ctx.HTML(http.StatusOK, tplActivity)
|
||
7 years ago
|
}
|
||
6 years ago
|
|
||
|
// 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)
|
||
5 years ago
|
case "quarterly":
|
||
|
timeFrom = timeUntil.AddDate(0, -3, 0)
|
||
|
case "semiyearly":
|
||
|
timeFrom = timeUntil.AddDate(0, -6, 0)
|
||
|
case "yearly":
|
||
|
timeFrom = timeUntil.AddDate(-1, 0, 0)
|
||
6 years ago
|
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
|
||
|
}
|
||
|
|
||
4 years ago
|
ctx.JSON(http.StatusOK, authors)
|
||
6 years ago
|
}
|