Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: A bot to run pre-commit and commit formatted code #211

Closed
sloria opened this issue Feb 4, 2019 · 8 comments
Closed

Idea: A bot to run pre-commit and commit formatted code #211

sloria opened this issue Feb 4, 2019 · 8 comments

Comments

@sloria
Copy link

sloria commented Feb 4, 2019

It would be great to have a GitHub bot that could execute pre-commit run ... on a PR then add a commit to the PR with the formatting changes, if there are any.

This would act as a last resort, ensuring that both maintainers and contributors don't need to care about formatting code.

Does this exist? If not, is there any interest in collaborating on something like this?

Prior discussions

@asottile
Copy link
Member

asottile commented Feb 4, 2019

Seems like a fine idea -- though I don't have the slightest idea on where to host such a thing however

I'm going to move this to the docs repo since it's less about the framework and more about ancillary tools.

I'd be happy to help set something like this up if there's interest and direction 👍

I believe @nicoddemus @RonnyPfannschmidt @obestwalter have expressed interest in a similar thing in the past as well, CCing them in case they have input

@asottile asottile transferred this issue from pre-commit/pre-commit Feb 4, 2019
@sloria
Copy link
Author

sloria commented Feb 4, 2019

Seems like a fine idea -- though I don't have the slightest idea on where to host such a thing however

The Probot docs have deployment instructions for Glitch, Heroku, Now, GH Actions, AWS Lambda, and Google Cloud Functions: https://probot.github.io/docs/deployment .

@sloria
Copy link
Author

sloria commented May 3, 2019

I wonder if this makes more sense as a GitHub Action. There's already actions implemented for a number of linters and formatters: https://github.com/bltavares/actions

@asottile
Copy link
Member

asottile commented May 3, 2019

I really really really want to set up a github action but I haven't been allowlisted into the beta yet :'(

@sloria
Copy link
Author

sloria commented Jul 2, 2019

The Restyled project (https://restyled.io/) uses GitHub actions to run formatters against PRs. I've suggested adding pre-commit support: restyled-io/restylers#29

@Pierre-Sassoulas
Copy link

This Github action would would save so much time. I found this existing action that look like a very close match. Maybe just adding pre-commit run --all-files would work:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
        fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
    - name: Create local changes
      run: |
        pre-commit run --all-files
    - name: Commit files
      run: |
        git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
        git config --local user.name "github-actions[bot]"
        git commit -m "Add changes" -a
    - name: Push changes
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ github.ref }}

@chriskuehl
Copy link
Member

@Pierre-Sassoulas have you seen https://pre-commit.ci/? It is developed by the primary pre-commit maintainer and sounds like exactly what you want.

@asottile
Copy link
Member

yeah this isn't possible to do safely with github actions -- so I made pre-commit.ci which is now the official way to run pre-commit in CI for github

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants