Skip to content

feat(repos): chart lines added and removed per week - #3637

Merged
Priyanshu-byte-coder merged 3 commits into
Priyanshu-byte-coder:mainfrom
officialasishkumar:feat/diff-trend-chart
Nov 14, 2026
Merged

Priyanshu-byte-coder merged 3 commits into
Priyanshu-byte-coder:mainfrom
officialasishkumar:feat/diff-trend-chart

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Summary

Adds a Lines Changed widget to the Repositories page: a stacked bar chart of the lines you added (green) and removed (red) each week over the last 12 weeks, summed across the 3 repositories you committed to most in that window. Commit counts alone hide how much code a week changed.

Closes #174


Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 📝 Documentation update
  • ♻️ Refactor / code cleanup (no functional change)
  • ⚡ Performance improvement
  • 🔒 Security fix
  • 🧪 Tests only

What Changed

  • src/app/api/metrics/diff-trend/route.ts (new): GET /api/metrics/diff-trend returns { weeks: [{ weekStart, additions, deletions }], repos }.
    • Repos are ranked from the shared commit timeline (collectAuthorCommits), so picking them costs no Search API calls. It honours the excluded-orgs setting the same way /api/metrics/repos does.
    • Line counts come from stats/contributors, filtered to the signed-in user. The issue suggested code_frequency, but that counts every contributor's lines, so in a shared repo it would credit other people's work to you.
    • Repos with nothing usable are skipped: empty (204), no longer accessible, the user not in GitHub's top-100 contributor list, or commits reported with zero lines (GitHub's 10,000+ commit limit).
    • While GitHub is still computing stats (202), the route answers 202 { computing: true }. That answer bypasses withMetricsCache, so the next request gets the real numbers.
    • Cached for 30 minutes (METRICS_CACHE_TTL_SECONDS["diff-trend"]). The dashboard refresh still bypasses the cache.
  • src/lib/diff-trend.ts (new): pure helpers for Sunday-aligned UTC week buckets (GitHub's w), repo ranking, author matching, missing-line detection, weekly sums and week-ending labels.
  • src/components/DiffTrendChart.tsx (new): Added / Removed / Net totals and a recharts stacked BarChart using var(--success) / var(--destructive), with a tooltip of exact counts per week ending date. It has loading, error (including rate limit), empty and "Computing stats…" states. The computing state has a Check again button; there is no background polling.
  • src/components/dashboard/widgets.tsx, src/app/dashboard/repositories/page.tsx: registers the lazy, mount-on-scroll DiffTrend slot and places it full-width under "Where your commits go".
  • public/openapi.yaml, docs/api.md, docs/caching.md, e2e/helpers/dashboard-mocks.js: add the new endpoint (pnpm api:check passes).
  • Tests: test/diff-trend.test.ts (helpers), test/diff-trend-route.test.ts (ranking, other authors ignored, out-of-window weeks ignored, excluded orgs, every skip case, uncached 202, revoked token) and test/components/DiffTrendChart.test.tsx (ready, computing → check again, rate limit, empty).

How to Test

  1. pnpm vitest run test/diff-trend.test.ts test/diff-trend-route.test.ts test/components/DiffTrendChart.test.tsx
  2. Sign in, open Dashboard → Repositories and scroll to Lines Changed.
  3. If GitHub hasn't computed stats for a repo yet, the widget shows "Computing stats…". Click Check again after a minute.

Expected result: a 12-week stacked bar chart of your own added/removed lines in your top 3 repos, named in the subtitle. Hovering a bar shows exact counts for that week.


Screenshots / Recordings

I checked it locally on /dashboard/repositories with mocked data at 1400px and 390px widths. The chart, tooltip, totals and the computing state all render with theme colours, and on phones the totals stay in one row of three.


Checklist

  • Linked the related issue above
  • Self-reviewed my own diff
  • No unnecessary console.log, debug code, or commented-out blocks
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Added or updated tests where applicable
  • Updated documentation / comments if behavior changed

Accessibility (UI changes only)

  • Keyboard navigation works correctly
  • Color contrast meets WCAG AA standard
  • ARIA labels / roles added where needed
  • Tested on mobile / responsive layout

Additional Context

  • The widget follows the signed-in account, like Repository Contribution Distribution on the same page. It doesn't take accountId.
  • On GitHub's side, stats/contributors lists at most 100 contributors and reports zero lines for repos with 10,000+ commits. Those repos are left out instead of being shown as zero.

Commit counts alone hide how much code a week actually changed, so the
Repositories page gets a "Lines Changed" widget: a stacked bar chart of
the lines the user added (green) and removed (red) in each of the last
12 weeks, summed across the 3 repositories they committed to most in
that window, with added / removed / net totals above it.

GET /api/metrics/diff-trend
- Ranks repositories from the shared commit timeline, so picking them
  costs no Search API calls, and honours the user's excluded orgs like
  the top repositories widget.
- Reads GET /repos/{owner}/{repo}/stats/contributors and keeps only the
  signed-in user's weeks. code_frequency counts every contributor's
  lines, which would credit other people's work to the user in shared
  repositories.
- Skips repositories with nothing usable: empty (204), no longer
  accessible, the user not among the 100 contributors GitHub lists, or
  commits reported with zero lines (GitHub's 10,000+ commit limit).
- Answers 202 { computing: true } while GitHub is still computing
  stats. That answer escapes the metrics cache, so the next request
  picks up the finished numbers; the widget shows "Computing stats…"
  with a Check again button instead of polling.
- Cached for 30 minutes like the other slow-moving metrics; the
  dashboard refresh still bypasses it.

The pure helpers (week bucketing, ranking, author matching, missing-line
detection) live in src/lib/diff-trend.ts with unit tests. The route and
the widget's ready, computing, rate-limited and empty states have tests
too. The OpenAPI spec, API and caching docs, and the shared e2e
dashboard mocks include the new endpoint.

Closes Priyanshu-byte-coder#174
@github-actions github-actions Bot added type:docs GSSoC type bonus: documentation (+5 pts) type:feature GSSoC type bonus: new feature type:testing GSSoC type bonus: tests (+10 pts) labels Nov 13, 2026
@github-actions

Copy link
Copy Markdown

Hi @officialasishkumar — thanks for the PR! 🙌

DevTrack asks contributors to ⭐ star the repo before a PR can be merged. It takes two seconds and is the easiest way to support the project.

Once you've starred, the star-required check turns green automatically (give it a moment). Thanks for contributing!

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

@officialasishkumar , your changes looks good in the recent prs ,so please star the repo which would help grow the project further and also would make the CI checks pass.
Thank you for contributing.

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

@officialasishkumar removed the star-required gate.
LGTM

@Priyanshu-byte-coder
Priyanshu-byte-coder merged commit f12cbb9 into Priyanshu-byte-coder:main Nov 14, 2026
13 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Merged! Thanks for contributing to DevTrack.

If the project has been useful to you, a ⭐ star on the repo is the easiest way to support it — it helps DevTrack get discovered by more developers.

Keep an eye on open issues for your next contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:docs GSSoC type bonus: documentation (+5 pts) type:feature GSSoC type bonus: new feature type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Add commit diff size trend — lines added/removed per week chart

2 participants