Skip to content

fix: return null deltaPercentage when previous month has zero contributions#913

Merged
JhaSourav07 merged 1 commit into
JhaSourav07:mainfrom
KaparthyReddy:fix/monthly-delta-undefined-baseline
May 28, 2026
Merged

fix: return null deltaPercentage when previous month has zero contributions#913
JhaSourav07 merged 1 commit into
JhaSourav07:mainfrom
KaparthyReddy:fix/monthly-delta-undefined-baseline

Conversation

@KaparthyReddy
Copy link
Copy Markdown
Contributor

Fixes #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

  • 🛠️ 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:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally.
  • I have run npm run format and npm run lint locally and resolved all errors.
  • My commits follow the Conventional Commits format.
  • I have updated README.md if I added a new theme or URL parameter.
  • I have starred the repo.
  • I have made sure that I have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard.
  • (Recommended) I joined the CommitPulse Discord community.

…utions

- Hardcoded +100% was misleading regardless of current month total
- deltaPercentage is now number | null in MonthlyStats type
- calculateMonthlyStats returns null when previousMonthTotal === 0
- generateMonthlySVG and generateAutoThemeMonthlySVG render 'N/A' for null
- Updated test to expect null instead of 100
@github-actions
Copy link
Copy Markdown

👋 Hey @KaparthyReddy, welcome to CommitPulse! 🎉

Thanks for opening your first pull request — this is a big deal and we appreciate the effort!

While you wait for a review, please double-check:

  • ✅ You've read the CONTRIBUTING.md checklist
  • npm run lint, npm run format, and npm run test all pass locally
  • ✅ Your PR has a visual preview if it touches any SVG output
  • 💬 You've joined our Discord for faster PR feedback

A maintainer will review your PR shortly. Hang tight! 🚀

@github-actions github-actions Bot added the type:bug Something isn't working as expected label May 28, 2026
@JhaSourav07 JhaSourav07 added GSSoC 2026 level:beginner Small changes Usually isolated fixes or simple UI/text updates. quality:exceptional Outstanding contribution with exceptional implementation quality, testing. gssoc:approved PR has been reviewed and accepted for valid contribution points mentor:Aamod007 labels May 28, 2026
@github-actions github-actions Bot added this to the GSSoC 2026 milestone May 28, 2026
@JhaSourav07 JhaSourav07 merged commit 0c97c14 into JhaSourav07:main May 28, 2026
15 of 16 checks passed
@github-actions
Copy link
Copy Markdown

🎉 Congratulations @KaparthyReddy! Your PR has been successfully merged. 🚀

Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.

⚠️ Important for GSSoC Contributors:
You are strictly advised to join our Discord Server as it is mandatory for all GSSoC participants. All important announcements, point claims, and community discussions happen there.

Keep building! 💻✨

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

Labels

gssoc:approved PR has been reviewed and accepted for valid contribution points GSSoC 2026 level:beginner Small changes Usually isolated fixes or simple UI/text updates. mentor:Aamod007 quality:exceptional Outstanding contribution with exceptional implementation quality, testing. type:bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] calculateMonthlyStats returns misleading +100% delta when previous month has zero contributions

3 participants