Add --json output mode (Bounty: $2 crypto)#51
Open
qlufiq-collab wants to merge 16 commits into
Open
Conversation
## Summary Add a `--json` flag to `git-context` so the generated repo context can be consumed programmatically. With `--json`, the tool emits a structured JSON document instead of the human-readable Markdown block, while preserving every existing flag and code path. ## Changes - `git-context` — Add `import json`, register `--json` argument, refactor `main()` to collect git/tree/file data once and branch on `--json` to either emit `json.dumps(..., indent=2)` or the existing Markdown sections. - `git_context/__init__.py` — Same change; this file is kept identical to the standalone script (it is the package entry point). ## Test Plan - `python3 git-context --json | python3 -m json.tool` → valid JSON with keys `repo`, `generated`, `path`, `git`, `log`, `branches`, `tree`. - `python3 git-context --json --files` → JSON document additionally contains a `files` key with source contents. - `python3 git-context --json -o /tmp/ctx.json` → writes valid JSON to disk; `json.load` succeeds. - `python3 git-context` → unchanged Markdown output (default text mode is untouched). - `python3 -m git_context --json` → module entry point produces the same JSON. ## Notes - Zero new dependencies; `json` is in the stdlib. - JSON shape: `git` is an object with `branch`, `remote`, `unstaged`, `staged`, `clean`; `log` and `branches` are arrays of lines for easy iteration; `tree` and `files` are kept as preformatted strings to match the existing rendering. - `--json` composes with `--depth`, `--files`, `--log`, `--output`, and `--dir`. Closes promptpolish-ai#2 Bounty: promptpolish-ai#2
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
[anti-stale]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
--jsonflag togit-contextso the generated repo context can be consumed programmatically. With--json, the tool emits a structured JSON document instead of the human-readable Markdown block, while preserving every existing flag and code path.Changes
git-context— Addimport json, register--jsonargument, refactormain()to collect git/tree/file data once and branch on--jsonto either emitjson.dumps(..., indent=2)or the existing Markdown sections.git_context/__init__.py— Same change; this file is kept identical to the standalone script (it is the package entry point).Test Plan
python3 git-context --json | python3 -m json.tool→ valid JSON with keysrepo,generated,path,git,log,branches,tree.python3 git-context --json --files→ JSON document additionally contains afileskey with source contents.python3 git-context --json -o /tmp/ctx.json→ writes valid JSON to disk;json.loadsucceeds.python3 git-context→ unchanged Markdown output (default text mode is untouched).python3 -m git_context --json→ module entry point produces the same JSON.Notes
jsonis in the stdlib.gitis an object withbranch,remote,unstaged,staged,clean;logandbranchesare arrays of lines for easy iteration;treeandfilesare kept as preformatted strings to match the existing rendering.--jsoncomposes with--depth,--files,--log,--output, and--dir.Closes #2