Commit 0c97c14
authored
fix: return null deltaPercentage when previous month has zero contributions (JhaSourav07#913)
Fixes JhaSourav07#908
## Description
`calculateMonthlyStats` in `lib/calculate.ts` hardcoded `deltaPercentage
= 100` whenever `previousMonthTotal === 0`, regardless of how many
contributions were made this month. This is mathematically undefined —
dividing by zero has no meaningful percentage result. A user with 1
commit vs 0 last month and a user with 500 commits vs 0 last month both
saw `+100%`, which is misleading and factually incorrect.
**Changes:**
- `deltaPercentage` is now typed as `number | null` in `MonthlyStats`
(`types/index.ts`)
- `calculateMonthlyStats` returns `null` when `previousMonthTotal === 0`
instead of hardcoded `100`
- `generateMonthlySVG` and `generateAutoThemeMonthlySVG` now render
`N/A` when `deltaPercentage` is `null`
- Updated existing test in `lib/calculate.test.ts` to expect `null`
instead of `100`
**Files changed:** `lib/calculate.ts`, `lib/svg/generator.ts`,
`types/index.ts`, `lib/calculate.test.ts`
## Pillar
- [x] 🛠️ Other (Bug fix, refactoring, docs)
## Visual Preview
N/A — delta indicator will now show `N/A` instead of `+100%` for users
with zero contributions last month.
## Checklist before requesting a review:
- [x] I have read the `CONTRIBUTING.md` file.
- [x] I have tested these changes locally.
- [x] I have run `npm run format` and `npm run lint` locally and
resolved all errors.
- [x] My commits follow the Conventional Commits format.
- [ ] I have updated `README.md` if I added a new theme or URL
parameter.
- [x] I have starred the repo.
- [x] I have made sure that I have only one commit to merge in this PR.
- [x] The SVG output matches the CommitPulse "premium quality" aesthetic
standard.
- [ ] (Recommended) I joined the CommitPulse Discord community.4 files changed
Lines changed: 41 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
379 | | - | |
| 379 | + | |
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
400 | 402 | | |
401 | 403 | | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
407 | 411 | | |
408 | 412 | | |
409 | 413 | | |
| |||
475 | 479 | | |
476 | 480 | | |
477 | 481 | | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
483 | 489 | | |
484 | 490 | | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
490 | 498 | | |
491 | 499 | | |
492 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
| 86 | + | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
0 commit comments