Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
git-pull-request

GitHub Action

rubocop-todo-corrector

v0.15.0

rubocop-todo-corrector

git-pull-request

rubocop-todo-corrector

Auto-correct RuboCop ToDo offenses and create pull request

Installation

Copy and paste the following snippet into your .yml file.

              

- name: rubocop-todo-corrector

uses: r7kamura/[email protected]

Learn more about this action in r7kamura/rubocop-todo-corrector

Choose a version

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:
    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 }}

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

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
    • Not required, but if you want to run another workflows from new pull request, you need to pass this token with workflow scope.

ignore

  • Ignore specific cop instead.
  • optional
  • e.g. "true"

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

  • Exclude unsafe cops.
  • default: "true"