{"id":22300341,"url":"https://github.com/dropseed/commitstat","last_synced_at":"2025-07-29T02:31:42.062Z","repository":{"id":47029373,"uuid":"373888722","full_name":"dropseed/commitstat","owner":"dropseed","description":"A lightweight tool for parsing changes in stats during CI builds (ex. code coverage) and reporting a pass/fail status in GitHub.","archived":false,"fork":false,"pushed_at":"2023-01-25T03:46:34.000Z","size":98,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-30T14:55:31.608Z","etag":null,"topics":["ci","code-coverage","coverage"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dropseed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-04T15:41:36.000Z","updated_at":"2022-12-21T19:15:04.000Z","dependencies_parsed_at":"2023-02-14T04:31:05.882Z","dependency_job_id":null,"html_url":"https://github.com/dropseed/commitstat","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropseed%2Fcommitstat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropseed%2Fcommitstat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropseed%2Fcommitstat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropseed%2Fcommitstat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dropseed","download_url":"https://codeload.github.com/dropseed/commitstat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227971951,"owners_count":17849421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci","code-coverage","coverage"],"created_at":"2024-12-03T18:10:34.806Z","updated_at":"2024-12-03T18:10:35.506Z","avatar_url":"https://github.com/dropseed.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# commitstat\n\nA CI tool for reporting and comparing stats on commits and pull requests.\nIt can parse a stat from a file or stdin,\ncheck whether the number has increased or decreased from the previous commit or main branch,\nand then report a pass/fail status on GitHub.\n\n```console\n$ commitstat coverage-report.txt --regex \"\\| Total\\s*\\|\\s*([\\d\\.]+%)\" --goal increase --name coverage\n```\n\nCan be used to check test coverage, typing coverage, file sizes, and more.\nThe status can be purely informative, or be set as a required status check (via GitHub branch protection) to ensure that something like test coverage doesn't get worse because of a pull request.\n\nThis is a lightweight alternative to hosted services like [Codecov](https://about.codecov.io/) and [Coveralls](https://coveralls.io/).\nAll of the data that commitstat uses is stored directly in the GitHub commit status and doesn't involve any third-party services or hosting.\nThere aren't any visualization tools built-in but you can always store artifacts in your CI provider or look at coverage reports locally.\n\n![commitstat on pull request checks](https://user-images.githubusercontent.com/649496/121754532-7df7b880-cada-11eb-8b0a-7457f0bb0ed8.png)\n\n## Quick install\n\nYou can install commitstat locally to test your parsing patterns, but commit statuses will only be created when run in CI.\n\n```console\n$ curl https://raw.githubusercontent.com/dropseed/commitstat/master/install.sh | bash -s -- -b $HOME/bin\n```\n\n## Options\n\n### `--name`\n\nThe name of the stat.\nWill show up as `commitstat/{name}` when submitted as a GitHub commit status.\nChanging the name for an existing stat will break the pass/fail comparison until the new name shows up on your main/master branch.\n\n### `--goal` (optional)\n\nEither \"increase\" or \"decrease\". This is the direction you *want* the stat to go. For example, test coverage should \"increase\" and if it actually decreases, then a failling status will be reported. If the stat is new or doesn't change, it is considered successful.\n\nIf you don't specify a goal, then you'll get a successful status and the stat/change will be purely informational.\n\n### `--regex` (optional)\n\nA regular expression to parse the file/stdin for a specific value.\nThere should be exactly one capture group in your regular expression (using parentheses) and you can include extra characters like a percent sign \"%\".\nThe extra characters will simply be removed when comparing the values (ex. \"36%\" will be interpreted as \"36\").\nYou'll receive an error if you mix units (ex. \"1mb\" and \"1gb\").\n\nBy default commitstat assumes the input is simply a number and a regex isn't needed (ex. `stat --format %s app.zip | commitstat -` on Ubuntu).\n\n## GitHub Action\n\nYou can run commitstat right after your tests and once you have some sort of stat to parse.\nUse different names to report multiple stats per commit.\n\n```yml\nname: test\n\non: [push]\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v2\n\n      # Run your tests, generate coverage files, etc.\n\n      - name: Install commitstat\n        run: curl https://raw.githubusercontent.com/dropseed/commitstat/master/install.sh | bash -s -- -b $HOME/bin\n\n      - name: Run commitstat\n        run: $HOME/bin/commitstat coverage-report.txt --regex \"\\| Total\\s*\\|\\s*([\\d\\.]+%)\" --goal increase --name coverage\n        env:\n          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n```\n\n## Example uses\n\n### mypy\n\nParse the [mypy](https://mypy.readthedocs.io/en/stable/command_line.html#report-generation) imprecision text report (lower number is better).\n\n```console\n$ mypy src --ignore-missing-imports --no-incremental --txt-report ./.reports/mypy\n$ commitstat .reports/mypy/index.txt --regex \"\\| Total\\s*\\|\\s*([\\d\\.]+%)\" --goal decrease --name mypy\n```\n\n### pytest-cov\n\nParse the [pytest-cov](https://github.com/pytest-dev/pytest-cov) default HTML report for the total coverage percentage.\n\n```console\n$ pytest --cov=src --cov-report=html:.reports/src/pytest src\n$ commitstat .reports/pytest/index.html --regex \"\u003cspan class=\\\"pc_cov\\\"\u003e(\\d+%)\u003c\\/span\u003e\" --goal increase --name pytest\n```\n\n### Go test coverage\n\nParse total test coverage from the [built-in go coverage tool](https://blog.golang.org/cover).\n\n```console\n$ go test ./... -coverprofile=coverage.out\n$ go tool cover -func coverage.out | commitstat - --regex \"total:\\s+\\(statements\\)\\s+([\\d\\.]+%)\" --goal increase --name coverage\n```\n\n### File sizes\n\nReport the size of a file (in bytes) using `stat` on Ubuntu (note that the options for stat can differ depending on your OS).\n\n```console\n$ stat --format %s app.zip | commitstat -\n```\n\n## How it works\n\nStats are stored directly in GitHub through the commit status API.\nThe stat is always the first number in the description which makes it easy to parse.\n\n\u003c!-- https://excalidraw.com/#json=5675361668956160,KJvEUJXgl5Sw7CV39_-04w --\u003e\n\n![commitstat git](https://user-images.githubusercontent.com/649496/121432738-a9df3680-c940-11eb-9a4f-a5be6e3fb05b.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropseed%2Fcommitstat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdropseed%2Fcommitstat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropseed%2Fcommitstat/lists"}