Skip to content

Implement DB-backed contributor stats with queued updates and UI sidebar contributors#37209

Open
lunny wants to merge 35 commits intogo-gitea:mainfrom
lunny:lunny/stats_rework
Open

Implement DB-backed contributor stats with queued updates and UI sidebar contributors#37209
lunny wants to merge 35 commits intogo-gitea:mainfrom
lunny:lunny/stats_rework

Conversation

@lunny
Copy link
Copy Markdown
Member

@lunny lunny commented Apr 14, 2026

Related to #30132
Fix #22129
Fix #7796

  • Replace git-log-based contributor stats with DB aggregation and daily storage.
  • Add contributor stats queues, cron backfill, and notifier-driven updates.
  • Provide commits-over-time endpoint and reuse stats for activity pulse data.
  • Add repository sidebar contributor avatars and split template for reuse.
  • Add tests covering contributors aggregation, activity stats, and commits-over-time.

A new option for Addtions + Deletions

image

Add time period for contributors

image

Add repository sidebar contributors

image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 14, 2026
@lunny lunny added the type/enhancement An improvement of existing functionality label Apr 16, 2026
@lunny lunny requested a review from Copilot April 18, 2026 07:04
@lunny
Copy link
Copy Markdown
Member Author

lunny commented Apr 18, 2026

It seems it's a good time to implement #29183 in this PR.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Locale rather 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.

Comment thread models/repo/contribution/contributor_daily.go Outdated
Comment thread services/repository/contributors_graph.go Outdated
Comment thread services/repository/contributors_stats.go Outdated
Comment thread modules/structs/contributor.go Outdated
Comment thread services/cron/tasks_extended.go
Comment thread services/repository/contributors_graph.go Outdated
@lunny lunny marked this pull request as ready for review April 22, 2026 22:34
@lunny lunny added this to the 1.27.0 milestone Apr 22, 2026
Comment thread services/repository/contributors_graph.go Outdated
@lunny lunny requested a review from a1012112796 May 3, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/enhancement An improvement of existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

list contributors for repository API Show contributors in repository summary (.ui.segment.sub-menu)

4 participants