本站源代码
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.

86 lines
2.3KB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "time"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/base"
  9. "code.gitea.io/gitea/modules/context"
  10. )
  11. const (
  12. tplActivity base.TplName = "repo/activity"
  13. )
  14. // Activity render the page to show repository latest changes
  15. func Activity(ctx *context.Context) {
  16. ctx.Data["Title"] = ctx.Tr("repo.activity")
  17. ctx.Data["PageIsActivity"] = true
  18. ctx.Data["Period"] = ctx.Params("period")
  19. timeUntil := time.Now()
  20. var timeFrom time.Time
  21. switch ctx.Data["Period"] {
  22. case "daily":
  23. timeFrom = timeUntil.Add(-time.Hour * 24)
  24. case "halfweekly":
  25. timeFrom = timeUntil.Add(-time.Hour * 72)
  26. case "weekly":
  27. timeFrom = timeUntil.Add(-time.Hour * 168)
  28. case "monthly":
  29. timeFrom = timeUntil.AddDate(0, -1, 0)
  30. default:
  31. ctx.Data["Period"] = "weekly"
  32. timeFrom = timeUntil.Add(-time.Hour * 168)
  33. }
  34. ctx.Data["DateFrom"] = timeFrom.Format("January 2, 2006")
  35. ctx.Data["DateUntil"] = timeUntil.Format("January 2, 2006")
  36. ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
  37. var err error
  38. if ctx.Data["Activity"], err = models.GetActivityStats(ctx.Repo.Repository, timeFrom,
  39. ctx.Repo.CanRead(models.UnitTypeReleases),
  40. ctx.Repo.CanRead(models.UnitTypeIssues),
  41. ctx.Repo.CanRead(models.UnitTypePullRequests),
  42. ctx.Repo.CanRead(models.UnitTypeCode)); err != nil {
  43. ctx.ServerError("GetActivityStats", err)
  44. return
  45. }
  46. ctx.HTML(200, tplActivity)
  47. }
  48. // ActivityAuthors renders JSON with top commit authors for given time period over all branches
  49. func ActivityAuthors(ctx *context.Context) {
  50. timeUntil := time.Now()
  51. var timeFrom time.Time
  52. switch ctx.Params("period") {
  53. case "daily":
  54. timeFrom = timeUntil.Add(-time.Hour * 24)
  55. case "halfweekly":
  56. timeFrom = timeUntil.Add(-time.Hour * 72)
  57. case "weekly":
  58. timeFrom = timeUntil.Add(-time.Hour * 168)
  59. case "monthly":
  60. timeFrom = timeUntil.AddDate(0, -1, 0)
  61. default:
  62. timeFrom = timeUntil.Add(-time.Hour * 168)
  63. }
  64. var err error
  65. authors, err := models.GetActivityStatsTopAuthors(ctx.Repo.Repository, timeFrom, 10)
  66. if err != nil {
  67. ctx.ServerError("GetActivityStatsTopAuthors", err)
  68. return
  69. }
  70. ctx.JSON(200, authors)
  71. }
上海开阖软件有限公司 沪ICP备12045867号-1