Skip to content

feat: Add badge subcommand for shields.io endpoint JSON generation #1

Description

@ynishi

Problem

When integrating codedash into CI pipelines (e.g., GitHub Actions), users need to generate badge data (shields.io endpoint JSON) for README badges. Currently this requires writing custom Python/shell scripts to parse codedash analyze -o json output and produce the correct JSON format.

Badge generation is a standard responsibility of metrics tools (e.g., cargo-tarpaulin --out badge), and codedash should support it natively.

Proposed Solution

Add a badge subcommand that outputs shields.io Endpoint Badge JSON files.

CLI Interface

codedash badge [OPTIONS] [path]

Arguments:
  [path]  Source directory (default: .)

Options:
  -o, --out-dir <dir>        Output directory (default: ./badges)
  -c, --config <config>      Config file path (.codedash.lua)
      --cov-file <cov-file>  Coverage JSON (cargo llvm-cov --json)
      --format <format>      Badge format: shields-endpoint (default), svg
      --only <metrics>       Comma-separated filter: coverage,fn-coverage,complexity,modules

Example Usage

codedash badge . --cov-file coverage.json -o _site/badges/

Output Files

badges/
  coverage.json       # line coverage %
  fn-coverage.json    # function coverage %
  complexity.json     # avg/max cyclomatic complexity
  modules.json        # total code units

Each file follows the shields.io endpoint format:

{
  "schemaVersion": 1,
  "label": "coverage",
  "message": "86.3%",
  "color": "brightgreen"
}

Color Logic

Metric Green Yellow Red
coverage >= 80% >= 60% < 60%
fn-coverage >= 80% >= 60% < 60%
complexity (avg) <= 5 <= 10 > 10
modules always blue

Configuration Override

Thresholds should be overridable via .codedash.lua:

return {
  extends = "recommended",
  badges = {
    coverage = { green = 80, yellow = 60 },
    complexity = { green = 5, yellow = 10 },
  },
}

CI Integration (Before/After)

# Before: custom Python script required
- run: |
    python3 <<'PY'
    import json
    cov = json.load(open("coverage.json"))
    # ... 20+ lines of badge generation logic
    PY

# After: single command
- run: codedash badge . --cov-file coverage.json -o _site/badges/

README Badge Embedding

![coverage](https://img.shields.io/endpoint?url=https://user.github.io/repo/badges/coverage.json)
![complexity](https://img.shields.io/endpoint?url=https://user.github.io/repo/badges/complexity.json)

Future Extensions

  • --format svg: self-contained SVG badge generation (no shields.io dependency)
  • Auto-embed badges into codedash view HTML output
  • Custom badge definitions in .codedash.lua badges section

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions