π Problem Statement
The README documents:
# Find complex code
codegraphcontext analyze complexity --threshold 10
This command returns functions whose cyclomatic complexity exceeds the
given threshold. However, the current output is human-readable text
only β there is no JSON, CSV, or machine-readable output mode.
Why This Is a CI/CD Blocker
The --threshold flag exists precisely for enforcement use cases:
"In this codebase, no function may have cyclomatic complexity above 10."
This is a standard quality gate in CI pipelines (similar to flake8's
--max-complexity flag).
But enforcing this in CI requires:
- A non-zero exit code when violations are found
- Machine-readable output that CI reporters can parse
Currently:
codegraphcontext analyze complexity --threshold 10 exits with code 0
regardless of how many violations are found.
- Output is formatted text, not parseable JSON.
- There is no way to integrate this with GitHub Actions, pytest, or any
standard CI tool.
Concrete CI Use Case That Currently Fails
# .github/workflows/quality.yml β this DOES NOT work today
- name: Check code complexity
run: |
codegraphcontext analyze complexity --threshold 10
# Always exits 0 β violations are never caught in CI
Compared to what users expect (the flake8 pattern):
- name: Check code complexity
run: flake8 --max-complexity=10 src/
# Exits non-zero when violations found β PR blocked
β
Proposed Solution
1. Non-zero exit code on threshold violations
# In src/codegraphcontext/analyzers/complexity.py
def analyze_complexity(threshold: int, output_format: str = "text") -> int:
"""
Returns number of violations found.
Caller should sys.exit(1) if violations > 0.
"""
violations = _find_violations(threshold)
_output(violations, output_format)
return len(violations)
# In CLI handler:
violations = analyze_complexity(threshold=args.threshold, output_format=args.format)
if violations > 0:
sys.exit(1) # β This is the critical missing line
2. --format flag for machine-readable output
# Human-readable (default, current behavior)
codegraphcontext analyze complexity --threshold 10
# JSON output for CI parsing
codegraphcontext analyze complexity --threshold 10 --format json
# CSV for spreadsheet/dashboard integration
codegraphcontext analyze complexity --threshold 10 --format csv
JSON output schema
{
"threshold": 10,
"violations_count": 3,
"violations": [
{
"function": "process_order",
"file": "src/orders.py",
"line": 45,
"complexity": 23,
"exceeds_by": 13
},
{
"function": "validate_input",
"file": "src/api/validators.py",
"line": 112,
"complexity": 17,
"exceeds_by": 7
}
]
}
3. GitHub Actions example in documentation
# docs/CI_INTEGRATION.md β new file
- name: Enforce complexity threshold
run: |
codegraphcontext index .
codegraphcontext analyze complexity --threshold 10 --format json \
| tee complexity-report.json
# Exits non-zero if any function exceeds threshold β PR blocked
- name: Upload complexity report
uses: actions/upload-artifact@v4
with:
name: complexity-report
path: complexity-report.json
Files to Modify
| File |
Change |
src/codegraphcontext/analyzers/complexity.py |
Return violation count, exit non-zero |
src/codegraphcontext/cli/analyze.py |
Add --format flag (json/csv/text) |
docs/CLI_COMPLETE_REFERENCE.md |
Document exit codes and --format |
docs/CI_INTEGRATION.md |
New β GitHub Actions integration guide |
tests/test_complexity.py |
Test exit codes and JSON output schema |
π Impact
The --threshold flag on analyze complexity currently has no
enforcement power β it describes violations but cannot block anything.
Adding exit codes and machine-readable output converts a reporting
tool into an enforcement tool, which is the primary use case for a
complexity threshold flag. This is directly analogous to the --exit-zero
pattern in flake8 and the --max-warnings pattern in ESLint, both of
which are standard CI tooling patterns.
Suggested labels: enhancement, CI/CD, intermediate
I would like to work on this. Could you assign it to me?
π Problem Statement
The README documents:
# Find complex code codegraphcontext analyze complexity --threshold 10This command returns functions whose cyclomatic complexity exceeds the
given threshold. However, the current output is human-readable text
only β there is no JSON, CSV, or machine-readable output mode.
Why This Is a CI/CD Blocker
The
--thresholdflag exists precisely for enforcement use cases:"In this codebase, no function may have cyclomatic complexity above 10."
This is a standard quality gate in CI pipelines (similar to flake8's
--max-complexityflag).But enforcing this in CI requires:
Currently:
codegraphcontext analyze complexity --threshold 10exits with code 0regardless of how many violations are found.
standard CI tool.
Concrete CI Use Case That Currently Fails
Compared to what users expect (the flake8 pattern):
β Proposed Solution
1. Non-zero exit code on threshold violations
2.
--formatflag for machine-readable outputJSON output schema
{ "threshold": 10, "violations_count": 3, "violations": [ { "function": "process_order", "file": "src/orders.py", "line": 45, "complexity": 23, "exceeds_by": 13 }, { "function": "validate_input", "file": "src/api/validators.py", "line": 112, "complexity": 17, "exceeds_by": 7 } ] }3. GitHub Actions example in documentation
Files to Modify
src/codegraphcontext/analyzers/complexity.pysrc/codegraphcontext/cli/analyze.py--formatflag (json/csv/text)docs/CLI_COMPLETE_REFERENCE.md--formatdocs/CI_INTEGRATION.mdtests/test_complexity.pyπ Impact
The
--thresholdflag onanalyze complexitycurrently has noenforcement power β it describes violations but cannot block anything.
Adding exit codes and machine-readable output converts a reporting
tool into an enforcement tool, which is the primary use case for a
complexity threshold flag. This is directly analogous to the
--exit-zeropattern in flake8 and the
--max-warningspattern in ESLint, both ofwhich are standard CI tooling patterns.
Suggested labels:
enhancement,CI/CD,intermediateI would like to work on this. Could you assign it to me?