gitea源码

code_frequency.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "errors"
  6. "net/http"
  7. "code.gitea.io/gitea/modules/templates"
  8. "code.gitea.io/gitea/services/context"
  9. contributors_service "code.gitea.io/gitea/services/repository"
  10. )
  11. const (
  12. tplCodeFrequency templates.TplName = "repo/activity"
  13. )
  14. // CodeFrequency renders the page to show repository code frequency
  15. func CodeFrequency(ctx *context.Context) {
  16. ctx.Data["Title"] = ctx.Tr("repo.activity.navbar.code_frequency")
  17. ctx.Data["PageIsActivity"] = true
  18. ctx.Data["PageIsCodeFrequency"] = true
  19. ctx.PageData["repoLink"] = ctx.Repo.RepoLink
  20. ctx.HTML(http.StatusOK, tplCodeFrequency)
  21. }
  22. // CodeFrequencyData returns JSON of code frequency data
  23. func CodeFrequencyData(ctx *context.Context) {
  24. if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch); err != nil {
  25. if errors.Is(err, contributors_service.ErrAwaitGeneration) {
  26. ctx.Status(http.StatusAccepted)
  27. return
  28. }
  29. ctx.ServerError("GetContributorStats", err)
  30. } else {
  31. ctx.JSON(http.StatusOK, contributorStats["total"].Weeks)
  32. }
  33. }