Skip to content

feat: codegraphcontext analyze complexity threshold flag has no documented output format and no machine-readable export — CI integration is impossible without parseable output #1333

Closed

Description

@divyanshim27

🚀 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:

  1. A non-zero exit code when violations are found
  2. 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?

Activity

  1. github-actions commented on Jun 28, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  2. aishwaryagangaraj-web commented on Jun 30, 2026

    @aishwaryagangaraj-web
    Contributor

    Hi @maintainers,

    I'd like to work on this issue. The proposed enhancement makes sense, and I'd be happy to implement support for machine-readable output (--format), appropriate exit codes for CI integration, tests, and the related documentation.

    Could you please assign this issue to me?

    Thank you!

  3. Sai-Ramya-prog commented on Jul 4, 2026

    @Sai-Ramya-prog

    /assign

  4. Sai-Ramya-prog commented on Jul 4, 2026

    @Sai-Ramya-prog

    I want to work on this issue can u please assign this under gssoc '26

  5. moved this from Backlog tasks to In progress in CGC Progress Boardon Aug 19, 2026
  6. moved this from In progress to Done in CGC Progress Boardon Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions