code.gitea.io/gitea@v1.22.3/routers/web/repo/recent_commits.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package repo 5 6 import ( 7 "errors" 8 "net/http" 9 10 "code.gitea.io/gitea/modules/base" 11 "code.gitea.io/gitea/services/context" 12 contributors_service "code.gitea.io/gitea/services/repository" 13 ) 14 15 const ( 16 tplRecentCommits base.TplName = "repo/activity" 17 ) 18 19 // RecentCommits renders the page to show recent commit frequency on repository 20 func RecentCommits(ctx *context.Context) { 21 ctx.Data["Title"] = ctx.Tr("repo.activity.navbar.recent_commits") 22 23 ctx.Data["PageIsActivity"] = true 24 ctx.Data["PageIsRecentCommits"] = true 25 ctx.PageData["repoLink"] = ctx.Repo.RepoLink 26 27 ctx.HTML(http.StatusOK, tplRecentCommits) 28 } 29 30 // RecentCommitsData returns JSON of recent commits data 31 func RecentCommitsData(ctx *context.Context) { 32 if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil { 33 if errors.Is(err, contributors_service.ErrAwaitGeneration) { 34 ctx.Status(http.StatusAccepted) 35 return 36 } 37 ctx.ServerError("RecentCommitsData", err) 38 } else { 39 ctx.JSON(http.StatusOK, contributorStats["total"].Weeks) 40 } 41 }