Skip to content

Commit b516a67

Browse files
committed
Introduce a new endpoint for fetching data in frontend
1 parent e29efb2 commit b516a67

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

routers/web/repo/contributors.go

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package repo
33
import (
44
"net/http"
55

6+
contributors_model "code.gitea.io/gitea/models/contributors"
67
"code.gitea.io/gitea/modules/base"
78
"code.gitea.io/gitea/modules/context"
89
)
@@ -28,3 +29,12 @@ func Contributors(ctx *context.Context) {
2829

2930
ctx.HTML(http.StatusOK, tplContributors)
3031
}
32+
33+
// ContributorsData renders JSON of contributors along with their weekly commit statistics
34+
func ContributorsData(ctx *context.Context) {
35+
if contributor_stats, err := contributors_model.GetContributorStats(ctx, ctx.Repo.Repository, ""); err != nil {
36+
ctx.ServerError("GetContributorStats", err)
37+
} else {
38+
ctx.JSON(http.StatusOK, contributor_stats)
39+
}
40+
}

routers/web/web.go

+1
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ func registerRoutes(m *web.Route) {
12471247
m.Group("/contributors", func() {
12481248
m.Get("", repo.Contributors)
12491249
m.Get("/{contribution_type}", repo.Contributors)
1250+
m.Get("/data", repo.ContributorsData)
12501251
}, context.RepoRef(), repo.MustBeNotEmpty, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases))
12511252

12521253
m.Group("/archive", func() {

web_src/js/components/RepoContributors.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const sfc = {
110110
methods: {
111111
async fetchGraphData() {
112112
this.isLoading = true;
113-
fetch(`/api/v1/repos/${this.repoLink}/contributors`)
113+
fetch(`${this.repoLink}/contributors/data`)
114114
.then((response) => response.json())
115115
.then((data) => {
116116
const {Total, ...rest} = data;

0 commit comments

Comments
 (0)