2017-10-14 17:17:39 -06:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 11:20:29 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-10-14 17:17:39 -06:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2021-04-05 09:30:52 -06:00
|
|
|
"net/http"
|
2017-10-14 17:17:39 -06:00
|
|
|
"time"
|
|
|
|
|
2022-08-24 20:31:57 -06:00
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
2021-11-09 12:57:58 -07:00
|
|
|
"code.gitea.io/gitea/models/unit"
|
2017-10-14 17:17:39 -06:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
2024-02-27 00:12:22 -07:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2017-10-14 17:17:39 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-02-15 15:21:13 -07:00
|
|
|
ctx.Data["PageIsPulse"] = true
|
|
|
|
|
2024-06-18 16:32:45 -06:00
|
|
|
ctx.Data["Period"] = ctx.PathParam("period")
|
2017-10-14 17:17:39 -06:00
|
|
|
|
|
|
|
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-04 22:45:48 -07: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 17:17:39 -06:00
|
|
|
default:
|
|
|
|
ctx.Data["Period"] = "weekly"
|
|
|
|
timeFrom = timeUntil.Add(-time.Hour * 168)
|
|
|
|
}
|
2024-11-01 22:08:28 -06:00
|
|
|
ctx.Data["DateFrom"] = timeFrom
|
|
|
|
ctx.Data["DateUntil"] = timeUntil
|
2017-10-14 17:17:39 -06:00
|
|
|
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
|
|
|
|
|
2017-10-15 15:54:53 -06:00
|
|
|
var err error
|
2022-08-24 20:31:57 -06:00
|
|
|
if ctx.Data["Activity"], err = activities_model.GetActivityStats(ctx, ctx.Repo.Repository, timeFrom,
|
2021-11-09 12:57:58 -07:00
|
|
|
ctx.Repo.CanRead(unit.TypeReleases),
|
|
|
|
ctx.Repo.CanRead(unit.TypeIssues),
|
|
|
|
ctx.Repo.CanRead(unit.TypePullRequests),
|
|
|
|
ctx.Repo.CanRead(unit.TypeCode)); err != nil {
|
2018-01-10 14:34:17 -07:00
|
|
|
ctx.ServerError("GetActivityStats", err)
|
2017-10-14 17:17:39 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-24 20:31:57 -06:00
|
|
|
if ctx.PageData["repoActivityTopAuthors"], err = activities_model.GetActivityStatsTopAuthors(ctx, ctx.Repo.Repository, timeFrom, 10); err != nil {
|
2020-01-20 03:07:30 -07:00
|
|
|
ctx.ServerError("GetActivityStatsTopAuthors", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-05 09:30:52 -06:00
|
|
|
ctx.HTML(http.StatusOK, tplActivity)
|
2017-10-14 17:17:39 -06:00
|
|
|
}
|
2019-05-04 06:39:03 -06: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
|
|
|
|
|
2024-06-18 16:32:45 -06:00
|
|
|
switch ctx.PathParam("period") {
|
2019-05-04 06:39:03 -06:00
|
|
|
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-04 22:45:48 -07: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 06:39:03 -06:00
|
|
|
default:
|
|
|
|
timeFrom = timeUntil.Add(-time.Hour * 168)
|
|
|
|
}
|
|
|
|
|
2022-08-24 20:31:57 -06:00
|
|
|
authors, err := activities_model.GetActivityStatsTopAuthors(ctx, ctx.Repo.Repository, timeFrom, 10)
|
2019-05-04 06:39:03 -06:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetActivityStatsTopAuthors", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-05 09:30:52 -06:00
|
|
|
ctx.JSON(http.StatusOK, authors)
|
2019-05-04 06:39:03 -06:00
|
|
|
}
|