Skip to content

feat: add JSON output option#3

Merged
mloncarevich merged 1 commit into
mainfrom
feat/json-output
Feb 9, 2026
Merged

feat: add JSON output option#3
mloncarevich merged 1 commit into
mainfrom
feat/json-output

Conversation

@mloncarevich

@mloncarevich mloncarevich commented Feb 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add --json / -j flag to output statistics as JSON
  • Useful for scripting, piping to jq, or integrating with other tools

Usage

# Pretty terminal output (default)
gitstats stats

# JSON output
gitstats stats --json

# Pipe to jq
gitstats stats --json | jq '.authors[0]'

Example output

{
  "repository": ".",
  "total_commits": 42,
  "total_authors": 3,
  "first_commit": "2024-01-15",
  "last_commit": "2026-02-06",
  "authors": [...],
  "weekly_activity": [...],
  "hourly_activity": [...]
}

Made with Cursor


Note

Low Risk
Primarily adds an alternate output format and small CLI branching; core parsing/stat computation is unchanged, so behavioral risk is limited to output/compat expectations.

Overview
Adds a --json/-j flag to gitstats stats to emit machine-readable JSON instead of the rich/pretty terminal output.

The JSON payload includes repository path, commit/author totals, first/last commit dates, per-author stats, and computed weekly/hourly activity; error cases now also return JSON when the flag is used. Documentation is updated to list the feature and show usage examples.

Written by Cursor Bugbot for commit 18470cd. This will update automatically on new commits. Configure here.

@mloncarevich mloncarevich merged commit 221bd0a into main Feb 9, 2026
5 of 6 checks passed

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on March 3

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Comment thread gitstats/cli.py
"weekly_activity": get_weekly_activity(stats_data["commits"]),
"hourly_activity": get_hourly_activity(stats_data["commits"]),
}
console.print(json.dumps(output, indent=2))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rich console.print corrupts machine-readable JSON output

High Severity

Using Rich's console.print for JSON output intended for machine consumption (jq, scripting) is incorrect. Rich's Console.print applies syntax highlighting (ANSI escape codes in terminal), soft-wraps text to the terminal/default width (breaking long JSON lines), and interprets Rich markup (square brackets in JSON values could be misinterpreted). All three behaviors can produce invalid JSON. Python's built-in print() is the appropriate choice here.

Additional Locations (1)

Fix in Cursor Fix in Web

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant