Skip to content
This repository was archived by the owner on Jan 11, 2021. It is now read-only.

Repository files navigation

gitbot-format - GitHub Action

Keeps your repo tidy by running clang-format on every PR.

Setup

Add the following to .github/workflows/pr.yaml:

name: PRon:
pull_request:
jobs:
checks:
runs-on: ubuntu-latestname: checkssteps:
- name: clang-formatid: clang-formatuses: tinybeachthor/gitbot-format@releases/v1with:
repo-token: ${{ secrets.GITHUB_TOKEN }}config-path: '.clang-format'

Enjoy automatic clang-format linting.

Optionally, to allow formatting, add .github/workflows/comment.yaml:

name: Commenton:
pull_request:
types:
- opened
- editedissue_comment:
types:
- created
- editedjobs:
format:
runs-on: ubuntu-latestname: Formatenv:
TAKE_ACTION: truesteps:
- name: Check for trigger worduses: khan/pull-request-comment-trigger@1.0.0id: triggerwith:
trigger: '/format'reaction: hoorayenv:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: clang-formatid: clang-formatuses: tinybeachthor/gitbot-format@releases/v1with:
repo-token: ${{ secrets.GITHUB_TOKEN }}config-path: '.clang-format'if: steps.trigger.outputs.triggered == 'true'

This will trigger auto-formatting whenever you comment /format in a PR.

Features

Respects repo stylefile

Just a regular .clang-format file in the root of the repo. Checks on the default branch first, PR branch second, and defaults to -style=Google if none found.

Only checks changed files

Only looks on files changed in a PR, so that it does not introduce extra changes from beyond the scope of the PR.

FAQ

Why prefer stylefile from the default branch to feature branch stylefile?

Since the goal is to keep the format of the whole codebase consistent, preferring the default branch stylefile will enforce the same style on all feature branches and make changes to the stylefile propagate instantly (no need to rebase every feature branch)

License

ISC © 2020 Martin Toman toman.martin@live.com

About

Automagically run clang-format on your PRs

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages