-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
action.yml
117 lines (111 loc) · 4.41 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: rubocop-todo-corrector
description: Auto-correct RuboCop ToDo offenses and create pull request.
inputs:
auto_merge:
description: Pass `"true"` if you want it to run `gh pr merge --auto --merge` after creating a pull request.
required: false
default: "false"
cop_name:
description: Pass cop name if you want to pick a specific cop.
required: false
default: ""
gh_pr_create_options:
description: Additional options for `gh pr create` command.
required: false
default: ""
github_token:
description: GitHub access token to run another workflows from new pull request.
required: false
ignore:
description: Ignore specific cop instead. ("cop_name" is required in this case)
required: false
default: "false"
label:
description: Pull request label name.
required: false
default: ""
mode:
description: Mode to select deletion target.
required: false
default: random
only_safe:
description: Exclude unsafe cops.
required: false
default: "true"
working_directory:
description: Working directory.
required: false
default: "."
runs:
using: composite
steps:
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: 3.1
- uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.base.ref }}" # We want to always get the default branch ref.
token: ${{ inputs.github_token || github.token }}
- name: Create pull request
run: |
if [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ github.event.action }}" == "closed" ]; then
if [ -z "${{ inputs.label }}" ]; then
echo "You need to set label input to use this feature."
exit 1
fi
if [ "${{ contains(github.event.pull_request.labels.*.name, inputs.label) }}" != "true" ]; then
echo "This pull request is unrelated because it's not labeled with ${{ inputs.label }} label."
exit 0
fi
open_pull_requests_count=$(gh pr list --label "${{ inputs.label }}" --json number --jq length)
if [ "$open_pull_requests_count" -gt 0 ]; then
echo "Other open labeled pull requests are still existing, so we don't create a new one."
exit 0
fi
fi
gem install --no-document rubocop_todo_corrector
if [ "${{ inputs.ignore }}" == "true" ]; then
if [ -z "${{ inputs.cop_name }}" ]; then
echo "You need to set cop_name input to use this feature."
exit 1
fi
echo 'Running: rubocop_todo_corrector ignore'
rubocop_todo_corrector ignore --cop-name "${{ inputs.cop_name }}"
description='Ignore `${{ inputs.cop_name }}` from rubocop-todo-corrector'
else
echo 'Running: rubocop_todo_corrector bundle'
rubocop_todo_corrector bundle
if [ -n "${{ inputs.cop_name }}" ]; then
cop_name="${{ inputs.cop_name }}"
else
cop_name=$(rubocop_todo_corrector pick --mode="${{ inputs.mode }}" ${{ inputs.only_safe != 'true' && '--no-only-safe' || '' }})
fi
echo 'Running: rubocop_todo_corrector remove'
rubocop_todo_corrector remove --cop-name="${cop_name}"
echo 'Running: rubocop_todo_corrector correct'
rubocop_todo_corrector correct ${{ inputs.only_safe != 'true' && '--no-only-safe' || '' }}
echo 'Running: rubocop_todo_corrector generate'
rubocop_todo_corrector generate
description=$(rubocop_todo_corrector describe --cop-name="${cop_name}")
echo 'Running: rubocop_todo_corrector clean'
rubocop_todo_corrector clean
fi
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
branch_name="rubocop-todo-corrector-${GITHUB_RUN_ID}"
git switch --create "${branch_name}"
git add .
git commit --message "${description}"
git push --set-upstream origin "${branch_name}"
gh pr create --fill --label="${{ inputs.label }}" ${{ inputs.gh_pr_create_options }}
if [ "${{ inputs.auto_merge }}" == "true" ]; then
gh pr merge --auto --merge
fi
env:
GITHUB_TOKEN: ${{ inputs.github_token || github.token }}
shell: bash
working-directory: ${{ inputs.working_directory }}
branding:
color: red
icon: git-pull-request