{"id":13532919,"url":"https://github.com/staabm/annotate-pull-request-from-checkstyle","last_synced_at":"2025-05-15T01:08:58.070Z","repository":{"id":37447765,"uuid":"234950208","full_name":"staabm/annotate-pull-request-from-checkstyle","owner":"staabm","description":"cs2pr - Annotate a GitHub Pull Request based on a Checkstyle XML-report within your GitHub Action","archived":false,"fork":false,"pushed_at":"2024-10-17T15:33:09.000Z","size":123,"stargazers_count":195,"open_issues_count":3,"forks_count":24,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-06T16:12:32.326Z","etag":null,"topics":["annotations","checkstyle","checkstyle-xml-report","cs2pr","githubaction","githubaction-workflow","hacktoberfest","php-cs-fixer","phpcs","phpstan","phpunit","pipe","psalm"],"latest_commit_sha":null,"homepage":"https://staabm.github.io/archive.html#cs2pr","language":"PHP","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/staabm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["staabm"]}},"created_at":"2020-01-19T19:04:50.000Z","updated_at":"2025-05-01T19:42:48.000Z","dependencies_parsed_at":"2025-02-07T12:06:21.771Z","dependency_job_id":"c5160fb2-2229-4d76-bce3-ca92e30da34d","html_url":"https://github.com/staabm/annotate-pull-request-from-checkstyle","commit_stats":{"total_commits":125,"total_committers":20,"mean_commits":6.25,"dds":0.36,"last_synced_commit":"2e1e12e8a393fd48737ecf58a4dc2e2ef42da618"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staabm%2Fannotate-pull-request-from-checkstyle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staabm%2Fannotate-pull-request-from-checkstyle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staabm%2Fannotate-pull-request-from-checkstyle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/staabm%2Fannotate-pull-request-from-checkstyle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/staabm","download_url":"https://codeload.github.com/staabm/annotate-pull-request-from-checkstyle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253009893,"owners_count":21839715,"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":["annotations","checkstyle","checkstyle-xml-report","cs2pr","githubaction","githubaction-workflow","hacktoberfest","php-cs-fixer","phpcs","phpstan","phpunit","pipe","psalm"],"created_at":"2024-08-01T07:01:14.970Z","updated_at":"2025-05-15T01:08:53.063Z","avatar_url":"https://github.com/staabm.png","language":"PHP","readme":"# Annotate a Pull Request based on a Checkstyle XML-report\n\n[![Continuous Integration](https://github.com/staabm/annotate-pull-request-from-checkstyle/workflows/Continuous%20Integration/badge.svg)](https://github.com/staabm/annotate-pull-request-from-checkstyle/actions)\n[![Continuous Deployment](https://github.com/staabm/annotate-pull-request-from-checkstyle/workflows/Continuous%20Deployment/badge.svg)](https://github.com/staabm/annotate-pull-request-from-checkstyle/actions)\n\nTurns [checkstyle based XML-Reports](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.0.2/doc/schemas/fix/checkstyle.xsd) into GitHub Pull Request [Annotations via the Checks API](https://docs.github.com/en/free-pro-team@latest/rest/reference/checks).\nThis script is meant for use within your GitHub Action.\n\nThat means you no longer search thru your GitHub Action logfiles.\nNo need to interpret messages which are formatted differently with every tool.\nInstead you can focus on your Pull Request, and you don't need to leave the Pull Request area.\n\n![Logs Example](https://github.com/mheap/phpunit-github-actions-printer/blob/master/phpunit-printer-logs.png?raw=true)\n\n![Context Example](https://github.com/mheap/phpunit-github-actions-printer/blob/master/phpunit-printer-context.png?raw=true)\n_Images from https://github.com/mheap/phpunit-github-actions-printer_\n\n[DEMO - See how Pull Request warnings/errors are rendered in action](https://github.com/staabm/gh-annotation-example/pull/1/files)\n\n# Installation\n\nInstall the binary via composer\n```bash\ncomposer require staabm/annotate-pull-request-from-checkstyle --dev\n```\n\n## 💌 Give back some love\n\n[Consider supporting the project](https://github.com/sponsors/staabm), so we can make this tool even better even faster for everyone.\n\n\n# Example Usage\n\n`cs2pr` can be used on a already existing checkstyle-report xml-file. Alternatively you might use it in the unix-pipe notation to chain it into your existing cli command.\n\nRun one of the following commands within your GitHub Action workflow:\n\n## Process a checkstyle formatted file\n\n```bash\ncs2pr /path/to/checkstyle-report.xml\n```\n\n### Available Options\n\n- `--graceful-warnings`: Don't exit with error codes if there are only warnings\n- `--colorize`: Colorize the output. Useful if the same lint script should be used locally on the command line and remote on GitHub Actions. With this option, errors and warnings are better distinguishable on the command line and the output is still compatible with GitHub Annotations\n- `--notices-as-warnings` Converts notices to warnings. This can be useful because GitHub does not annotate notices. \n- `--prepend-filename` Prepend the filename to the output message\n- `--prepend-source` When the checkstyle generating tool provides a `source` attribute, prepend the source to the output message. \n\n\n## Pipe the output of another commmand\n\n... works for __any__ command which produces a checkstyle-formatted report.\n\nExamples can bee seen below:\n\n### Using [PHPStan](https://github.com/phpstan/phpstan)\n\n```bash\nphpstan analyse --error-format=checkstyle | cs2pr\n```\n\n_Phpstan 0.12.32 introduced native github actions support, therefore you might use this instead:_\n\n```bash\nphpstan analyse\n```\n\n### Using [Psalm](https://github.com/vimeo/psalm)\n\n```bash\npsalm --output-format=checkstyle | cs2pr\n```\n\n_Psalm even supports the required format natively, therefore you might use this instead:_\n\n```bash\npsalm --output-format=github\n```\n\n### Using [PHP Coding Standards Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)\n\n```bash\nphp-cs-fixer fix --dry-run --format=checkstyle | cs2pr\n```\n\n### Using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)\n\n```bash\nphpcs --report=checkstyle -q /path/to/code | cs2pr\n```\n\n\nNote: the `-q` option means that no output will be shown in the action logs anymore.\nTo see the output both in the PR as well as in the action logs, use two steps, like so:\n\n```yaml\n      - name: Check PHP code style\n        id: phpcs\n        run: phpcs --report-full --report-checkstyle=./phpcs-report.xml\n\n      - name: Show PHPCS results in PR\n        if: ${{ always() \u0026\u0026 steps.phpcs.outcome == 'failure' }}\n        run: cs2pr ./phpcs-report.xml\n```\n\n### Using [PHP Parallel Lint](https://github.com/php-parallel-lint/PHP-Parallel-Lint/)\n\n```bash\nvendor/bin/parallel-lint . --exclude vendor --checkstyle | cs2pr\n```\n\n### Using [Laravel Pint](https://github.com/laravel/pint)\n\n```yaml\n- name: Show Pint results in PR\nrun: pint --test --format=checkstyle | cs2pr\n```\n\nNote: if you want to have both logs and annotations you need to run `pint` twice:\n\n```yaml\n- name: Check PHP code style\nid: cs-check\nrun: pint --test\n\n- name: Generate Annotations on CS errors\nif: failure() \u0026\u0026 steps.cs-check.outcome != 'success'\nrun: pint --test --format=checkstyle | cs2pr\n```\n\n## phpunit support?\n\nPHPUnit does not support checkstyle, therefore `cs2pr` will not work for you.\n\nyou might instead try\n- a [phpunit problem matcher](https://github.com/shivammathur/setup-php#problem-matchers)\n- a [phpunit-github-actions-printer](https://github.com/mheap/phpunit-github-actions-printer)\n\n## Example GithubAction workflow\n\n\nIf you're using `shivammathur/setup-php` to setup PHP, `cs2pr` binary is shipped within:\n\n```yml\n# ...\njobs:\n    phpstan-analysis:\n      name: phpstan static code analysis\n      runs-on: ubuntu-latest\n      steps:\n          - uses: actions/checkout@v2\n          - name: Setup PHP\n            uses: shivammathur/setup-php@v1\n            with:\n                php-version: 7.3\n                coverage: none # disable xdebug, pcov\n                tools: cs2pr\n          - run: |\n                composer install # install your apps dependencies\n                vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr\n```\n\nIf you use a custom PHP installation, then your project needs to require `staabm/annotate-pull-request-from-checkstyle`\n\n```yml\n# ...\njobs:\n    phpstan-analysis:\n      name: phpstan static code analysis\n      runs-on: ubuntu-latest\n      steps:\n          - uses: actions/checkout@v2\n          - name: Setup PHP\n            run: # custom PHP installation \n          - run: |\n                composer install # install your apps dependencies\n                composer require staabm/annotate-pull-request-from-checkstyle # install cs2pr\n                vendor/bin/phpstan analyse --error-format=checkstyle | vendor/bin/cs2pr\n```\n\n## Using cs2pr as a GitHub Action\n\nYou can also use [`cs2pr` itself as a GitHub Action](https://github.com/staabm/annotate-pull-request-from-checkstyle-action). This is useful if you want to for instance use it for a project that does not use PHP or if you want to use it with a custom PHP installation.\n\nSee the example at the [cs2pr GitHub Action repositiory](https://github.com/staabm/annotate-pull-request-from-checkstyle-action#readme).\n\n\n\n# Resources\n\n[GithubAction Problem Matchers](https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md)\n\n# Idea\n\nThis script is based on a suggestion of [Benjamin Eberlei](https://twitter.com/beberlei/status/1218970454557372416)\n\nThe Code is inspired by https://github.com/mheap/phpunit-github-actions-printer\n","funding_links":["https://github.com/sponsors/staabm"],"categories":["PHP","Community Resources"],"sub_categories":["Pull Requests"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstaabm%2Fannotate-pull-request-from-checkstyle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstaabm%2Fannotate-pull-request-from-checkstyle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstaabm%2Fannotate-pull-request-from-checkstyle/lists"}