Skip to content

Commit e9be8b2

Browse files
sahinakkayasilverwindhiifongdelvh6543
authored andcommitted
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 <[email protected]> Co-authored-by: hiifong <[email protected]> Co-authored-by: delvh <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: yp05327 <[email protected]> (cherry picked from commit 21331be)
1 parent 1f8ad34 commit e9be8b2

File tree

18 files changed

+1330
-230
lines changed

18 files changed

+1330
-230
lines changed

options/locale/locale_en-US.ini

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,6 +1957,8 @@ wiki.page_name_desc = Enter a name for this Wiki page. Some special names are: '
19571957
wiki.original_git_entry_tooltip = View original Git file instead of using friendly link.
19581958

19591959
activity = Activity
1960+
activity.navbar.pulse = Pulse
1961+
activity.navbar.contributors = Contributors
19601962
activity.period.filter_label = Period:
19611963
activity.period.daily = 1 day
19621964
activity.period.halfweekly = 3 days
@@ -2022,6 +2024,16 @@ activity.git_stats_and_deletions = and
20222024
activity.git_stats_deletion_1 = %d deletion
20232025
activity.git_stats_deletion_n = %d deletions
20242026

2027+
contributors = Contributors
2028+
contributors.contribution_type.filter_label = Contribution type:
2029+
contributors.contribution_type.commits = Commits
2030+
contributors.contribution_type.additions = Additions
2031+
contributors.contribution_type.deletions = Deletions
2032+
contributors.loading_title = Loading contributions...
2033+
contributors.loading_title_failed = Could not load contributions
2034+
contributors.loading_info = This might take a bit…
2035+
contributors.component_failed_to_load = An unexpected error happened.
2036+
20252037
search = Search
20262038
search.search_repo = Search repository
20272039
search.type.tooltip = Search type

package-lock.json

Lines changed: 64 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 44 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,10 @@ func registerRoutes(m *web.Route) {
14311431
m.Group("/activity", func() {
14321432
m.Get("", repo.Activity)
14331433
m.Get("/{period}", repo.Activity)
1434+
m.Group("/contributors", func() {
1435+
m.Get("", repo.Contributors)
1436+
m.Get("/data", repo.ContributorsData)
1437+
})
14341438
}, context.RepoRef(), repo.MustBeNotEmpty, context.RequireRepoReaderOr(unit.TypePullRequests, unit.TypeIssues, unit.TypeReleases))
14351439

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

0 commit comments

Comments
 (0)