Skip to content

Commit 5d0c26d

Browse files
sahinakkayasilverwindhiifongdelvh6543
committed
Implement contributors graph (go-gitea#27882)
Continuation of go-gitea#25439. Fixes go-gitea#847 Before: <img width="1296" alt="image" src="https://github.com/go-gitea/gitea/assets/32161460/24571ac8-b254-43c9-b178-97340f0dc8a9"> ---- After: <img width="1296" alt="image" src="https://github.com/go-gitea/gitea/assets/32161460/c60b2459-9d10-4d42-8d83-d5ef0f45bf94"> --- #### Overview This is the implementation of a requested feature: Contributors graph (go-gitea#847) It makes Activity page a multi-tab page and adds a new tab called Contributors. Contributors tab shows the contribution graphs over time since the repository existed. It also shows per user contribution graphs for top 100 contributors. Top 100 is calculated based on the selected contribution type (commits, additions or deletions). --- #### Demo (The demo is a bit old but still a good example to show off the main features) <video src="https://github.com/go-gitea/gitea/assets/32161460/9f68103f-8145-4cc2-94bc-5546daae7014" controls width="320" height="240"> <a href="https://github.com/go-gitea/gitea/assets/32161460/9f68103f-8145-4cc2-94bc-5546daae7014">Download</a> </video> #### Features: - Select contribution type (commits, additions or deletions) - See overall and per user contribution graphs for the selected contribution type - Zoom and pan on graphs to see them in detail - See top 100 contributors based on the selected contribution type and selected time range - Go directly to users' profile by clicking their name if they are registered gitea users - Cache the results so that when the same repository is visited again fetching data will be faster --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: hiifong <i@hiif.ong> Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: yp05327 <576951401@qq.com>
1 parent 116205d commit 5d0c26d

18 files changed

+1330
-230
lines changed

options/locale/locale_en-US.ini

+12
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,8 @@ wiki.page_name_desc = Enter a name for this Wiki page. Some special names are: '
19121912
wiki.original_git_entry_tooltip = View original Git file instead of using friendly link.
19131913

19141914
activity = Activity
1915+
activity.navbar.pulse = Pulse
1916+
activity.navbar.contributors = Contributors
19151917
activity.period.filter_label = Period:
19161918
activity.period.daily = 1 day
19171919
activity.period.halfweekly = 3 days
@@ -1977,6 +1979,16 @@ activity.git_stats_and_deletions = and
19771979
activity.git_stats_deletion_1 = %d deletion
19781980
activity.git_stats_deletion_n = %d deletions
19791981

1982+
contributors = Contributors
1983+
contributors.contribution_type.filter_label = Contribution type:
1984+
contributors.contribution_type.commits = Commits
1985+
contributors.contribution_type.additions = Additions
1986+
contributors.contribution_type.deletions = Deletions
1987+
contributors.loading_title = Loading contributions...
1988+
contributors.loading_title_failed = Could not load contributions
1989+
contributors.loading_info = This might take a bit…
1990+
contributors.component_failed_to_load = An unexpected error happened.
1991+
19801992
search = Search
19811993
search.search_repo = Search repository
19821994
search.type.tooltip = Search type

package-lock.json

+64-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
"add-asset-webpack-plugin": "2.0.1",
1919
"ansi_up": "6.0.2",
2020
"asciinema-player": "3.6.3",
21+
"chart.js": "4.3.0",
22+
"chartjs-adapter-dayjs-4": "1.0.4",
23+
"chartjs-plugin-zoom": "2.0.1",
2124
"clippie": "4.0.6",
2225
"css-loader": "6.10.0",
26+
"dayjs": "1.11.10",
2327
"dropzone": "6.0.0-beta.2",
2428
"easymde": "2.18.0",
2529
"esbuild-loader": "4.0.3",
@@ -46,6 +50,7 @@
4650
"uint8-to-base64": "0.2.0",
4751
"vue": "3.4.18",
4852
"vue-bar-graph": "2.0.0",
53+
"vue-chartjs": "5.3.0",
4954
"vue-loader": "17.4.2",
5055
"vue3-calendar-heatmap": "2.0.5",
5156
"webpack": "5.90.1",

routers/web/repo/activity.go

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func Activity(ctx *context.Context) {
2222
ctx.Data["Title"] = ctx.Tr("repo.activity")
2323
ctx.Data["PageIsActivity"] = true
2424

25+
ctx.Data["PageIsPulse"] = true
26+
2527
ctx.Data["Period"] = ctx.Params("period")
2628

2729
timeUntil := time.Now()

routers/web/repo/contributors.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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/modules/context"
12+
contributors_service "code.gitea.io/gitea/services/repository"
13+
)
14+
15+
const (
16+
tplContributors base.TplName = "repo/activity"
17+
)
18+
19+
// Contributors render the page to show repository contributors graph
20+
func Contributors(ctx *context.Context) {
21+
ctx.Data["Title"] = ctx.Tr("repo.contributors")
22+
23+
ctx.Data["PageIsActivity"] = true
24+
ctx.Data["PageIsContributors"] = true
25+
26+
ctx.PageData["contributionType"] = "commits"
27+
28+
ctx.PageData["repoLink"] = ctx.Repo.RepoLink
29+
30+
ctx.HTML(http.StatusOK, tplContributors)
31+
}
32+
33+
// ContributorsData renders JSON of contributors along with their weekly commit statistics
34+
func ContributorsData(ctx *context.Context) {
35+
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
36+
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
37+
ctx.Status(http.StatusAccepted)
38+
return
39+
}
40+
ctx.ServerError("GetContributorStats", err)
41+
} else {
42+
ctx.JSON(http.StatusOK, contributorStats)
43+
}
44+
}

routers/web/web.go

+4
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,10 @@ func registerRoutes(m *web.Route) {
13921392
m.Group("/activity", func() {
13931393
m.Get("", repo.Activity)
13941394
m.Get("/{period}", repo.Activity)
1395+
m.Group("/contributors", func() {
1396+
m.Get("", repo.Contributors)
1397+
m.Get("/data", repo.ContributorsData)
1398+
})
13951399
}, context.RepoRef(), repo.MustBeNotEmpty, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases))
13961400

13971401
m.Group("/activity_author_data", func() {

0 commit comments

Comments
 (0)