Coder Social home page Coder Social logo

rubocop-todo-corrector's Introduction

rubocop-todo-corrector

Custom action to create a pull request that autocorrects offenses in .rubocop_todo.yml per cop.

Usage

Add the following workflow file to manually run the action:

# .github/workflows/rubocop-todo-corrector.yml
name: rubocop-todo-corrector

on:
  workflow_dispatch:

jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - uses: r7kamura/rubocop-todo-corrector@v0

Now you can run it via actions page:

or if you want to do it from CLI, use GitHub CLI like this:

gh workflow run rubocop-todo-corrector

After the action is complete, a pull request is created as follows:

Automatic running

By adding on.pull_request event to the workflow, you can automatically run it when all other labeled pull requests are merged or closed.

 name: rubocop-todo-corrector

 on:
+  pull_request:
+     types:
+       - closed
   workflow_dispatch:
     inputs:
       cop_name:
         description: Pass cop name if you want to pick a specific cop.
         required: false
         type: string
       ignore:
         description: Check this with cop_name if you want to ignore a specific cop.
         required: false
         type: boolean
 jobs:
   run:
     runs-on: ubuntu-latest
     steps:
       - uses: r7kamura/rubocop-todo-corrector@v0
         with:
           ignore: ${{ inputs.ignore }}
+          label: rubocop-todo-corrector

Note that the label input is required to use this feature.

Don't forget to create the label on your repository before you run the action.

label

Ignore cops

If you pass ignore as "true", the action will create a pull request that ignores the specified cop by appending specified cop_name to .rubocop_todo_corrector_ignore.

Note: You can ignore specific cops by adding a file named .rubocop_todo_corrector_ignore to your repository. See the following page for more details:

Inputs

auto_merge

  • Pass "true" if you want it to run gh pr merge --auto --merge after creating a pull request.
  • optional

cop_name

  • Pass cop name if you want to pick a specific cop.
  • optional
    • Required if ignore is "true"
  • e.g. "Style/NegatedIf"

gh_pr_create_options

  • Additional options for gh pr create command.
  • optional
  • e.g. "--reviewer r7kamura --draft"

github_token

  • GitHub access token for GitHub API calls.
  • optional

It uses the default GitHub access token, so it usually works well as is without any additional configuration. However, there is a known issue that the default access token does not have workflow scope, so the pull request created by this action cannot run other GitHub Actions workflows. In that case, pass a custom access token with this option:

If a personal access token is used, the permission would look like this:

  • repo
  • workflow

If you use GitHub App to generate access tokens, the permission would look like this:

  • Actions: Read/Write
  • Contents: Read/Write
  • Issues: Read (necessary for GitHub API permission bug)
  • Members: Read (optional for reviewer assignment)
  • Pull Requests: Read/Write

ignore

  • Pass "true" if you want to create a pull request to ignore a specific cop instead.
  • optional

label

  • Pull request label name.
  • optional
  • e.g. "rubocop-todo-corrector"
  • Note: You need to create a label with this name on your repository.

mode

  • Mode to select autocorrected cop.
  • default: "random"
  • Choose from the following options:
    • "first"
    • "last"
    • "least_occurred"
    • "most_occurred"
    • "random"

only_safe

  • Pass "false" if you want it to include unsafe autocorrection.
  • optional

working_directory

  • Specify working directory.
  • optional
  • default: "."

Example

The below example is how we use this in our company:

on:
  pull_request:
    types:
      - closed
  workflow_dispatch:
    inputs:
      cop_name:
        description: Pass cop name if you want to pick a specific cop.
        required: false
        type: string
      ignore:
        description: Check this with cop_name if you want to ignore a specific cop.
        required: false
        type: boolean

jobs:
  run:
    runs-on: ubuntu-latest
    steps:
      - uses: tibdex/github-app-token@v1
        with:
          app_id: ${{ secrets.OUR_GITUB_APP_ID }}
          private_key: ${{ secrets.OUR_GITUB_APP_PRIVATE_KEY }}
        id: github_app_token
      - uses: r7kamura/rubocop-todo-corrector@v0
        with:
          cop_name: ${{ inputs.cop_name }}
          gh_pr_create_options: "--reviewer our-org/rubocop-reviewers"
          github_token: ${{ steps.github_app_token.outputs.token }}
          ignore: ${{ inputs.ignore }}
          label: rubocop-todo-corrector

rubocop-todo-corrector's People

Contributors

r7kamura avatar takenori-sasa avatar yasuzuki avatar ydah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rubocop-todo-corrector's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.