/python-black-pull-request-action

A GitHub Action that runs the Python Black formatter but only on files that changed in the PR

Primary LanguageShellMIT LicenseMIT

Readme

This is a github action that will run the black python formatter 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. Entrypoint code is inspired by the excellent typilus.

Installation

To install, create a GitHub Actions Workflow:

name: Black Check

# 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.

    etc...
      - uses: rgasper/python-black-pull-request-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          LINE_LENGTH: 1000 # please don't do this