mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 12:15:43 +01:00
c54896ba70
When all repository units are deactivated except for the code unit, the activity tab will not be shown. Since the activities tab also shows contributing stats, it would be good to show the activities tab also when only code is active. This commit changes the behavior when the activities tab is shown. Previous it would only be shown when Issues, Pull-Requests or Releases are activated. Now it would additionally be shown when the code unit is activated. Refs: #3429 | Before (Code + Issues - Owner) | Before (Code - Viewer) | After (Code + Issues - Owner) | After (Code - Viewer) | | -- | -- | -- | -- | | ![image](/attachments/2af997bc-1f38-48c6-bdf3-cfbd7087b220) | ![image](/attachments/ef1797f0-5c9a-4a1a-ba82-749f3ab4f403) | ![image](/attachments/fd28a96c-04ca-407e-a70d-d28b393f223d) | ![image](/attachments/2cd0d559-a6de-4ca0-a736-29c5fea81b5a) | | | `/activity` returns 404 for everyone | ![image](/attachments/e0e97d8f-48cb-4c16-a505-1fafa46c4b8e) | - | Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3455 Reviewed-by: Otto <otto@codeberg.org> Co-authored-by: Beowulf <beowulf@beocode.eu> Co-committed-by: Beowulf <beowulf@beocode.eu>
105 lines
2.9 KiB
Go
105 lines
2.9 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
|
"code.gitea.io/gitea/models/unit"
|
|
"code.gitea.io/gitea/modules/base"
|
|
"code.gitea.io/gitea/services/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["PageIsPulse"] = 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)
|
|
case "quarterly":
|
|
timeFrom = timeUntil.AddDate(0, -3, 0)
|
|
case "semiyearly":
|
|
timeFrom = timeUntil.AddDate(0, -6, 0)
|
|
case "yearly":
|
|
timeFrom = timeUntil.AddDate(-1, 0, 0)
|
|
default:
|
|
ctx.Data["Period"] = "weekly"
|
|
timeFrom = timeUntil.Add(-time.Hour * 168)
|
|
}
|
|
ctx.Data["DateFrom"] = timeFrom.UTC().Format(time.RFC3339)
|
|
ctx.Data["DateUntil"] = timeUntil.UTC().Format(time.RFC3339)
|
|
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
|
|
|
|
var err error
|
|
if ctx.Data["Activity"], err = activities_model.GetActivityStats(ctx, ctx.Repo.Repository, timeFrom,
|
|
ctx.Repo.CanRead(unit.TypeReleases),
|
|
ctx.Repo.CanRead(unit.TypeIssues),
|
|
ctx.Repo.CanRead(unit.TypePullRequests),
|
|
ctx.Repo.CanRead(unit.TypeCode) && !ctx.Repo.Repository.IsEmpty); err != nil {
|
|
ctx.ServerError("GetActivityStats", err)
|
|
return
|
|
}
|
|
|
|
if ctx.PageData["repoActivityTopAuthors"], err = activities_model.GetActivityStatsTopAuthors(ctx, ctx.Repo.Repository, timeFrom, 10); err != nil {
|
|
ctx.ServerError("GetActivityStatsTopAuthors", err)
|
|
return
|
|
}
|
|
|
|
ctx.HTML(http.StatusOK, 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)
|
|
case "quarterly":
|
|
timeFrom = timeUntil.AddDate(0, -3, 0)
|
|
case "semiyearly":
|
|
timeFrom = timeUntil.AddDate(0, -6, 0)
|
|
case "yearly":
|
|
timeFrom = timeUntil.AddDate(-1, 0, 0)
|
|
default:
|
|
timeFrom = timeUntil.Add(-time.Hour * 168)
|
|
}
|
|
|
|
var err error
|
|
authors, err := activities_model.GetActivityStatsTopAuthors(ctx, ctx.Repo.Repository, timeFrom, 10)
|
|
if err != nil {
|
|
ctx.ServerError("GetActivityStatsTopAuthors", err)
|
|
return
|
|
}
|
|
|
|
ctx.JSON(http.StatusOK, authors)
|
|
}
|