Repository navigation
feat(repos): chart lines added and removed per week - #3637
Priyanshu-byte-coder merged 3 commits into
Conversation
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
|
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 |
|
@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. |
|
@officialasishkumar removed the star-required gate. |
f12cbb9
into
Priyanshu-byte-coder:main
|
🎉 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! |
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
What Changed
src/app/api/metrics/diff-trend/route.ts(new):GET /api/metrics/diff-trendreturns{ weeks: [{ weekStart, additions, deletions }], repos }.collectAuthorCommits), so picking them costs no Search API calls. It honours the excluded-orgs setting the same way/api/metrics/reposdoes.stats/contributors, filtered to the signed-in user. The issue suggestedcode_frequency, but that counts every contributor's lines, so in a shared repo it would credit other people's work to you.202 { computing: true }. That answer bypasseswithMetricsCache, so the next request gets the real numbers.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'sw), 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 stackedBarChartusingvar(--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-scrollDiffTrendslot 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:checkpasses).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) andtest/components/DiffTrendChart.test.tsx(ready, computing → check again, rate limit, empty).How to Test
pnpm vitest run test/diff-trend.test.ts test/diff-trend-route.test.ts test/components/DiffTrendChart.test.tsxExpected 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/repositorieswith 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
console.log, debug code, or commented-out blocksnpm run lintpasses locallynpm run type-check)Accessibility (UI changes only)
Additional Context
accountId.stats/contributorslists 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.