Skip to content

A Github Action to run Flake8 lint check in your project with every PR, and comment the lines with trespassing

Notifications You must be signed in to change notification settings

matias-martini/flake8-pr-comments-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flake8 Pull Request Commenter

Flake8 Pull Request Commenter is a GitHub Action that comments on pull requests with Flake8 linting errors. The action runs Flake8 on the changed files whenever a pull request is opened or updated, and creates a comment to the pull request on every code line where an error was found. This makes it easy for developers to see and fix any linting errors in their code before merging the pull request.

image

Why Use Flake8?

Flake8 is a popular Python linter that checks your code for common issues such as syntax errors, code style violations, and unused imports. Using Flake8 helps to ensure that your code is clean, readable, and consistent, making it easier for other developers to understand and work with.

Usage

To use Flake8 Pull Request Commenter in your repository, you'll need to create a new workflow file that triggers the action on pull request events. Setting up a new workflow can be done by creating a new YML file in .github/workflows

Here's an example workflow file that you can use as a starting point:

#  .github/workflows/YOUR-WORKFLOW.yml

name: comment_pr_with_linter_error

on: [pull_request]

jobs:
  flake8-lint:
    permissions:
      pull-requests: write
    runs-on: ubuntu-latest
    name: Linter
    steps:
      - name: Check out source repository
        uses: actions/checkout@v3
      - name: Set up Python environment
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - name: Run linter and comment PR
        uses: matias-martini/flake8-pr-comments-action@main
        with:
          github_token: ${{ github.token }}

Configuration

To better fit your usage, this GitHub Action allows you to configure one required and two optional parameters.

  • github_token: This is an authorization token that grants pull request write access to make it possible to write review comments in the PR. By default, you can use the token generated by the action itself (${{ github.token }}). However, you can use any other token that has more granular permissions.
  • cfg_path: This parameter specifies the path to your project's flake8 configuration file. For example: src/.flake8. This is useful if you have a custom configuration file that you would like to use. If this parameter is not set, the action will default to using the global flake8 configuration file.
  • plugins: The next parameter allows you to specify names of flake8 plugins that you would like to use to expand its functionality. Each plugin should be specified by its name as they are found and installed via pip. If you want to use more than one plugin, you can separate the names using spaces. For example, pep8-naming flake8-functions.

Here's an example that uses all two parameters to provide a clear understanding of how they can be used together:

name: comment_pr_with_linter_error

on: [pull_request]

jobs:
  flake8-lint:
    permissions:
      pull-requests: write
    runs-on: ubuntu-latest
    name: Lint
    steps:
      - name: Check out source repository
        uses: actions/checkout@v3
      - name: Set up Python environment
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - name: Run linter and comment PR
        uses: matias-martini/flake8-pr-comments-action@main
        with:
          github_token: ${{ github.token }}
          cfg_path: "src/.flake8"
          plugins: "pep8-naming flake8-functions"

In this example, we are using the plugins pep8-naming and flake8-functions to extend Flake8's functionality. Additionally, we are specifying the configuration file src/.flake8, which has the following contents:

[flake8]
max-line-length = 100
max-function-length = 20

Contributing

All kind of contributions are welcome! If you have any issues or feature requests, please open an issue on this GitHub repository.

If you'd like to contribute code, please fork the repository and submit a pull request. The project has some automated tests and uses this very action to check the linting 🙃

About

A Github Action to run Flake8 lint check in your project with every PR, and comment the lines with trespassing

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages