Skip to content

classify: bucket commits by message convention #3

@simon-marcus

Description

@simon-marcus

Implement `commitlens classify` — count commits by Conventional-Commits-style category prefix.

Deliverable

Module: `src/commitlens/classify.py`. Register in `_register_subcommands`.

Output schema

```json
{
"_render": "",
"buckets": {
"feat": {"count": 23, "share": 0.31},
"fix": {"count": 18, "share": 0.24},
"docs": {"count": 7, "share": 0.09},
"refactor": {"count": 4, "share": 0.05},
"test": {"count": 2, "share": 0.03},
"chore": {"count": 5, "share": 0.07},
"other": {"count": 16, "share": 0.21}
},
"total_commits": 75
}
```

Classifier rules

A commit's category is determined by the first line of its message:

  • Match `^(feat|fix|docs|refactor|test|chore|perf|build|ci|style|revert)(\(.+\))?!?:` (case-sensitive) — strip the trailing colon-space and bucket the prefix. Treat `perf`, `build`, `ci`, `style`, `revert` as `other` for v1 (don't add their own bucket).
  • Otherwise → `other`.

`share` is rounded to 2 decimal places.

Human render

A markdown-ish list:

```
feat 23 31% ###################
fix 18 24% ###############
docs 7 9% ######
...
```

Bar width: `int(round(50 * share))`. Total at the bottom.

Tests

`tests/test_classify.py` using `git_repo`. Build commits with varied prefixes including `feat:`, `fix(auth):`, `fix!:`, `docs:`, plain `update README` (other), `perf:` (should bucket as other), and assert the right counts and shares.

Metadata

Metadata

Assignees

No one assigned

    Labels

    symphonyCreated by Symphony

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions