diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8711877 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3 + +RUN pip install black + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b93f004 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# Readme + +This is a github action that will run the [black python formatter](https://github.com/psf/black) on a PR, but only on the files changed in your PR. This helps avoid situations where one runs the formatter on an old code base and gets hundreds of files with warnings and hints. + +## Installation + +To install, create a GitHub Actions Workflow: + +```yaml +name: Black + +# Run action on PRs to master +on: + pull_request: + branches: [ master ] + +jobs: + suggest: + runs-on: ubuntu-latest + + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so that black can inspect it + - uses: actions/checkout@v2 + - uses: rgasper/python-black-pull-request-action@master + env: + GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} +``` + +## Configuration + +By default, runs black with all default configurations except for `--line-length 130`, because 88 characters feels a bit small. This can be changed by assigning the argument in the Workflow. + +```yaml + etc... + - uses: rgasper/python-black-pull-request-action@master + env: + GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} + with: + line-length: 1000 # please don't do this +``` diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..9fac2ac --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# TODO make this actually work, probably just convert into pythong +list_of_edited_files=`./git_diff_to_get_list_of_edited_files` +black ${list_of_edited_files} \ No newline at end of file