Implement DB-backed contributor stats with queued updates and UI sidebar contributors#37209
Open
lunny wants to merge 35 commits intogo-gitea:mainfrom
Open
Implement DB-backed contributor stats with queued updates and UI sidebar contributors#37209lunny wants to merge 35 commits intogo-gitea:mainfrom
lunny wants to merge 35 commits intogo-gitea:mainfrom
Conversation
…s sidebar in repository home page
Member
Author
|
It seems it's a good time to implement #29183 in this PR. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR migrates contributor/activity statistics from git-log based, on-demand computation to DB-backed daily aggregates with queued updates, adds a commits-over-time endpoint, and surfaces contributors in the repository sidebar and contributors UI.
Changes:
- Introduces DB tables and aggregation/query APIs for contributor daily/weekly stats, plus queues + notifier + cron backfill for generating/updating stats.
- Updates web endpoints and UI charts to consume DB-backed “commits/code frequency/contributors” data (including new “additions + deletions” mode and time-range filter).
- Adds API endpoint + swagger schema for listing repository contributors with stats, and updates tests accordingly.
Reviewed changes
Copilot reviewed 42 out of 42 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| web_src/js/utils/time.ts | Normalizes computed week start timestamps to UTC midnight. |
| web_src/js/utils/color.ts | Adds chart color key for combined additions+deletions series. |
| web_src/js/components/RepoRecentCommits.vue | Switches to new “commits over time” semantics and data handling. |
| web_src/js/components/RepoContributors.vue | Adds time-range filter and combined additions+deletions contribution type. |
| web_src/js/components/RepoCodeFrequency.vue | Improves single-point chart rendering. |
| tests/integration/api_repo_contributors_test.go | Adds integration coverage for new contributors API stats fields. |
| tests/integration/api_admin_test.go | Updates cron task count expectations due to new cron task. |
| templates/swagger/v1_json.tmpl | Adds swagger path + schemas for contributors endpoint and fields. |
| templates/repo/pulse.tmpl | Updates pulse template to use new DB-backed commit counts/fields. |
| templates/repo/home_sidebar_contributors.tmpl | New sidebar partial rendering top contributor avatars. |
| templates/repo/home_sidebar_bottom.tmpl | Includes contributors sidebar partial on repo home. |
| services/repository/repository.go | Initializes contributor stats queues during repository service init. |
| services/repository/contributors_stats.go | Implements queues + update/rebuild processing and daily stat generation. |
| services/repository/contributors_over_time.go | Adds weekly totals query for “commits over time” and similar charts. |
| services/repository/contributors_over_time_test.go | Unit tests for weekly totals aggregation. |
| services/repository/contributors_notify.go | Hooks push/default-branch changes to enqueue stats updates/rebuilds. |
| services/repository/contributors_graph.go | Replaces cache/git-log contributor stats with DB-backed aggregation. |
| services/repository/contributors_graph_test.go | Updates contributor graph tests and adds parser + gitstats tests. |
| services/cron/tasks_extended.go | Adds daily cron to enqueue rebuilds for repos missing contributor stats. |
| routers/web/web.go | Routes recent-commits data to new handler. |
| routers/web/repo/view_home.go | Prepares repo-home sidebar contributor data. |
| routers/web/repo/recent_commits.go | Adds RecentCommitsData endpoint powered by weekly stats. |
| routers/web/repo/contributors.go | Adds from/to query params and switches to DB-backed contributor stats. |
| routers/web/repo/code_frequency.go | Switches code-frequency JSON to weekly DB stats. |
| routers/api/v1/api.go | Registers new API route for listing contributors. |
| routers/api/v1/repo/contributors.go | Implements contributors API endpoint returning stats + user info. |
| routers/api/v1/swagger/repo.go | Adds swagger response type for ContributorList. |
| options/locale/locale_en-US.json | Adds admin locale key for rebuild contributor stats cron. |
| modules/structs/repo_commit.go | Adds changed_files to commit stats struct. |
| modules/structs/contributor.go | Adds Contributor API struct + custom JSON marshaling. |
| models/git/repo_stats.go | Removes old git-based code activity stats implementation. |
| modules/git/repo_stats_test.go | Removes tests tied to old git-based code activity stats. |
| models/user/list.go | Moves/introduces GetUsersMapByIDs/GetPossibleUserFromMap into main list file. |
| models/user/user_list.go | Removes now-duplicated user list helpers file. |
| models/repo/contribution/main_test.go | Adds TestMain for contribution model tests. |
| models/repo/contribution/contributor_meta.go | Adds repo_contributor_meta model for tracking processing state. |
| models/repo/contribution/contributor_daily.go | Adds repo_contributor_daily model and query/update APIs. |
| models/repo/contribution/contributor_daily_test.go | Adds comprehensive tests for contributor stats aggregation APIs. |
| models/migrations/v1_27/v331.go | Adds migration creating contributor daily/meta tables. |
| models/migrations/migrations.go | Registers migration 331. |
| models/activities/repo_activity.go | Switches activity code stats/top authors to DB-backed contributor daily stats. |
| models/activities/repo_activity_test.go | Adds tests for DB-backed activity code stats. |
Comments suppressed due to low confidence (2)
web_src/js/components/RepoRecentCommits.vue:1
- Removing the previous
.slice(-52)means the chart may render an unbounded number of weeks (potentially years), which can noticeably degrade chart rendering performance and UX in large repos. Consider reintroducing a reasonable cap (or a default range) and/or adding server-side date range parameters so the endpoint returns a bounded window by default.
web_src/js/components/RepoContributors.vue:1 - The dropdown labels should use proper pluralization (“Months”) for values > 1, and ideally be localized via
ctx.Localerather than hardcoded English strings. Updating these strings improves UX and keeps i18n consistent with the rest of the page.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]> Signed-off-by: Lunny Xiao <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Lunny Xiao <[email protected]>
a1012112796
reviewed
Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #30132
Fix #22129
Fix #7796
A new option for Addtions + Deletions
Add time period for contributors
Add repository sidebar contributors