rubocop_challenger 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +12 -20
- data/.rubocop_todo.yml +3 -2
- data/Gemfile.lock +1 -1
- data/README.md +31 -16
- data/images/circleci_environment_variables.png +0 -0
- data/images/generate_token.png +0 -0
- data/lib/rubocop_challenger.rb +2 -3
- data/lib/rubocop_challenger/cli.rb +51 -11
- data/lib/rubocop_challenger/github/pr_template.rb +36 -0
- data/lib/rubocop_challenger/rubocop/command.rb +4 -0
- data/lib/rubocop_challenger/version.rb +1 -1
- data/lib/templates/default.md.erb +6 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ba8deecbf49b350474a9144e4a1bf8f31d50d287e5dd51f0c3685ad01f86c17
|
4
|
+
data.tar.gz: 4c8eef6d0c2d989a8b566b9989364a594f9d874f4c2750096b73dafa8954f6dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb9a03b11502c7d5169d8082af81af23d603480ca2de1d2bf216fb40fdcc7caf3142466121a93065f4e3754f43ec6c2a3a2fa8c8b166ad2745a9c2c656f38acc
|
7
|
+
data.tar.gz: ec425dcd9f57d26241be0e304f983c656db68cef4e6a9386bc7ef1685ff6700efa1927a14290d6b1558106244e426f4ced6561039f7f669d2be2e4937782b515
|
data/.circleci/config.yml
CHANGED
@@ -78,8 +78,7 @@ jobs:
|
|
78
78
|
docker:
|
79
79
|
- image: circleci/ruby:2.3-node-browsers
|
80
80
|
<<: *rubocop
|
81
|
-
|
82
|
-
rubocop_challenge:
|
81
|
+
verify_rubocop_challenge:
|
83
82
|
docker:
|
84
83
|
- image: circleci/ruby:2.3-node-browsers
|
85
84
|
working_directory: ~/repo
|
@@ -90,14 +89,16 @@ jobs:
|
|
90
89
|
- *save_bundle_install_cache
|
91
90
|
- run: bundle exec rake install
|
92
91
|
- run:
|
93
|
-
name: Rubocop Challenge
|
92
|
+
name: Verify Rubocop Challenge
|
94
93
|
command: |
|
95
94
|
bundle exec exe/rubocop_challenger go \
|
96
95
|
--email=ryz310@gmail.com \
|
97
96
|
--name=ryz310 \
|
98
|
-
--mode=random
|
97
|
+
--mode=random \
|
98
|
+
--regenerate-rubocop-todo \
|
99
|
+
--no-commit
|
99
100
|
|
100
|
-
|
101
|
+
rubocop_challenge:
|
101
102
|
docker:
|
102
103
|
- image: circleci/ruby:2.3-node-browsers
|
103
104
|
working_directory: ~/repo
|
@@ -106,10 +107,11 @@ jobs:
|
|
106
107
|
- run:
|
107
108
|
name: Rubocop Challenge
|
108
109
|
command: |
|
109
|
-
gem install rubocop_challenger
|
110
|
+
gem install -N rubocop_challenger
|
110
111
|
rubocop_challenger go \
|
111
112
|
--email=ryz310@gmail.com \
|
112
|
-
--name=ryz310
|
113
|
+
--name=ryz310 \
|
114
|
+
--regenerate-rubocop-todo
|
113
115
|
|
114
116
|
release:
|
115
117
|
docker:
|
@@ -142,17 +144,7 @@ workflows:
|
|
142
144
|
- build_on_ruby_2.5
|
143
145
|
- build_on_ruby_latest
|
144
146
|
- rubocop
|
145
|
-
-
|
146
|
-
requires:
|
147
|
-
- build_on_ruby_2.3
|
148
|
-
- build_on_ruby_2.4
|
149
|
-
- build_on_ruby_2.5
|
150
|
-
- build_on_ruby_latest
|
151
|
-
- rubocop
|
152
|
-
filters:
|
153
|
-
branches:
|
154
|
-
only:
|
155
|
-
- master
|
147
|
+
- verify_rubocop_challenge
|
156
148
|
- release:
|
157
149
|
context: RubyGems API Key
|
158
150
|
requires:
|
@@ -169,10 +161,10 @@ workflows:
|
|
169
161
|
challenge:
|
170
162
|
triggers:
|
171
163
|
- schedule:
|
172
|
-
cron: "30 23 * *
|
164
|
+
cron: "30 23 * * *" # 8:30am every day (JST)
|
173
165
|
filters:
|
174
166
|
branches:
|
175
167
|
only:
|
176
168
|
- master
|
177
169
|
jobs:
|
178
|
-
-
|
170
|
+
- rubocop_challenge
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2018-10-
|
3
|
+
# on 2018-10-22 15:21:40 +0900 using RuboCop version 0.59.2.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -27,13 +27,14 @@ RSpec/ExampleLength:
|
|
27
27
|
Exclude:
|
28
28
|
- 'spec/rubocop_challenger/rubocop/todo_reader_spec.rb'
|
29
29
|
|
30
|
-
# Offense count:
|
30
|
+
# Offense count: 8
|
31
31
|
Style/Documentation:
|
32
32
|
Exclude:
|
33
33
|
- 'spec/**/*'
|
34
34
|
- 'test/**/*'
|
35
35
|
- 'lib/rubocop_challenger.rb'
|
36
36
|
- 'lib/rubocop_challenger/cli.rb'
|
37
|
+
- 'lib/rubocop_challenger/github/pr_template.rb'
|
37
38
|
- 'lib/rubocop_challenger/rubocop/challenge.rb'
|
38
39
|
- 'lib/rubocop_challenger/rubocop/command.rb'
|
39
40
|
- 'lib/rubocop_challenger/rubocop/rule.rb'
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,12 +10,24 @@ I call such work *Rubocop Challenge*. And the *RubocopChallenger* is a gem to su
|
|
10
10
|
## Rubocop Challenge Flow
|
11
11
|
|
12
12
|
1. Run *RubocopChallenger* periodically from CI tool etc.
|
13
|
-
|
14
|
-
|
13
|
+
1. When *RubocopChallenger* starts, delete a disabled rule from `.rubocop_todo.yml` existing in your project, execute `$ rubocop --auto-correct` and create a PR which include modified results
|
14
|
+
1. You confirm the PR passes testing and then merge it if there is no problem
|
15
15
|
|
16
|
-
##
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
### 1. Setting GitHub personal access token
|
19
|
+
|
20
|
+
GitHub personal access token is required for sending pull requests to your repository.
|
17
21
|
|
18
|
-
|
22
|
+
1. Go to [your account's settings page](https://github.com/settings/tokens) and [generate a new token](https://github.com/settings/tokens/new) with "repo" scope
|
23
|
+

|
24
|
+
1. On [CircleCI](https://circleci.com) dashboard, go to your application's "Project Settings" -> "Environment Variables"
|
25
|
+
1. Add an environment variable `GITHUB_ACCESS_TOKEN` with your GitHub personal access token
|
26
|
+

|
27
|
+
|
28
|
+
### 2. Configure .circleci/config.yml
|
29
|
+
|
30
|
+
Configure your `.circleci/config.yml` to run rubocop_challenger, for example:
|
19
31
|
|
20
32
|
```yml
|
21
33
|
# .circleci/config.yml
|
@@ -31,7 +43,7 @@ jobs:
|
|
31
43
|
- run:
|
32
44
|
name: Rubocop Challenge
|
33
45
|
command: |
|
34
|
-
gem install rubocop_challenger
|
46
|
+
gem install -N rubocop_challenger
|
35
47
|
rubocop_challenger go \
|
36
48
|
--email=rubocop-challenge@example.com \
|
37
49
|
--name="'Rubocop Challenge'"
|
@@ -51,7 +63,7 @@ workflows:
|
|
51
63
|
- rubocop_challenge
|
52
64
|
```
|
53
65
|
|
54
|
-
##
|
66
|
+
## CLI command references
|
55
67
|
|
56
68
|
```sh
|
57
69
|
$ rubocop_challenger help
|
@@ -71,16 +83,18 @@ Usage:
|
|
71
83
|
rubocop_challenger go --email=EMAIL --name=NAME
|
72
84
|
|
73
85
|
Options:
|
74
|
-
--email=EMAIL
|
75
|
-
--name=NAME
|
76
|
-
f, [--file-path=FILE_PATH]
|
77
|
-
|
78
|
-
[--mode=MODE]
|
79
|
-
|
80
|
-
[--base=BASE]
|
81
|
-
|
82
|
-
l, [--labels=one two three]
|
83
|
-
|
86
|
+
--email=EMAIL # Pull Request committer email
|
87
|
+
--name=NAME # Pull Request committer name
|
88
|
+
f, [--file-path=FILE_PATH] # Set your ".rubocop_todo.yml" path
|
89
|
+
# Default: .rubocop_todo.yml
|
90
|
+
[--mode=MODE] # Mode to select deletion target. You can choice "most_occurrence", "least_occurrence", or "random"
|
91
|
+
# Default: most_occurrence
|
92
|
+
[--base=BASE] # Base branch of Pull Request
|
93
|
+
# Default: master
|
94
|
+
l, [--labels=one two three] # Label to give to Pull Request
|
95
|
+
# Default: ["rubocop challenge"]
|
96
|
+
[--regenerate-rubocop-todo], [--no-regenerate-rubocop-todo] # Rerun `$ rubocop --auto-gen-config` after autocorrect
|
97
|
+
[--no-commit] # No commit after autocorrect
|
84
98
|
|
85
99
|
Run `$ rubocop --auto-correct` and create PR to your GitHub repository
|
86
100
|
```
|
@@ -88,6 +102,7 @@ Run `$ rubocop --auto-correct` and create PR to your GitHub repository
|
|
88
102
|
## Requirement
|
89
103
|
|
90
104
|
* Ruby 2.3 or higher
|
105
|
+
* NOTE: Ruby 2.3 will EOL soon (See: [Ruby Maintenance Branches](https://www.ruby-lang.org/en/downloads/branches/))
|
91
106
|
|
92
107
|
## Development
|
93
108
|
|
Binary file
|
Binary file
|
data/lib/rubocop_challenger.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'erb'
|
3
4
|
require 'rubocop'
|
4
5
|
require 'rubocop-rspec'
|
5
6
|
require 'rubocop_challenger/rubocop/rule'
|
@@ -9,7 +10,5 @@ require 'rubocop_challenger/rubocop/command'
|
|
9
10
|
require 'rubocop_challenger/rubocop/challenge'
|
10
11
|
require 'rubocop_challenger/cli'
|
11
12
|
require 'rubocop_challenger/version'
|
13
|
+
require 'rubocop_challenger/github/pr_template.rb'
|
12
14
|
require 'pr-daikou'
|
13
|
-
|
14
|
-
module RubocopChallenger
|
15
|
-
end
|
@@ -32,11 +32,21 @@ module RubocopChallenger
|
|
32
32
|
default: ['rubocop challenge'],
|
33
33
|
aliases: :l,
|
34
34
|
desc: 'Label to give to Pull Request'
|
35
|
+
option :'regenerate-rubocop-todo',
|
36
|
+
type: :boolean,
|
37
|
+
default: false,
|
38
|
+
desc: 'Rerun `$ rubocop --auto-gen-config` after autocorrect'
|
39
|
+
option :'no-commit',
|
40
|
+
type: :boolean,
|
41
|
+
default: false,
|
42
|
+
desc: 'No commit after autocorrect'
|
35
43
|
def go
|
36
|
-
target_rule =
|
37
|
-
|
44
|
+
target_rule = rubocop_challenge
|
45
|
+
regenerate_rubocop_todo
|
46
|
+
create_pull_request(target_rule)
|
38
47
|
rescue StandardError => e
|
39
48
|
puts e.message
|
49
|
+
exit!
|
40
50
|
end
|
41
51
|
|
42
52
|
desc 'version', 'Show current version'
|
@@ -44,24 +54,54 @@ module RubocopChallenger
|
|
44
54
|
puts RubocopChallenger::VERSION
|
45
55
|
end
|
46
56
|
|
57
|
+
module ClassMethods
|
58
|
+
# Workaround to return exit code 1 when an error occurs
|
59
|
+
# @see https://github.com/erikhuda/thor/issues/244
|
60
|
+
def exit_on_failure?
|
61
|
+
true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
47
65
|
private
|
48
66
|
|
49
|
-
def
|
67
|
+
def rubocop_challenge
|
68
|
+
Rubocop::Challenge.exec(options[:file_path], options[:mode])
|
69
|
+
end
|
70
|
+
|
71
|
+
def regenerate_rubocop_todo
|
72
|
+
return unless options[:'regenerate-rubocop-todo']
|
73
|
+
|
74
|
+
Rubocop::Command.new.auto_gen_config
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_pull_request(rule)
|
78
|
+
pr_daikou_options = generate_pr_daikou_options(rule)
|
79
|
+
return if options[:'no-commit']
|
80
|
+
|
81
|
+
PRDaikou.exec(pr_daikou_options, nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_pr_daikou_options(target_rule)
|
50
85
|
{
|
51
|
-
email:
|
52
|
-
name:
|
53
|
-
base:
|
54
|
-
title:
|
55
|
-
|
56
|
-
|
57
|
-
|
86
|
+
email: options[:email],
|
87
|
+
name: options[:name],
|
88
|
+
base: options[:base],
|
89
|
+
title: target_rule.title,
|
90
|
+
description: pr_template(target_rule),
|
91
|
+
labels: options[:labels].join(','),
|
92
|
+
topic: generate_topic(target_rule),
|
93
|
+
commit: ":robot: #{target_rule.title}"
|
58
94
|
}
|
59
95
|
end
|
60
96
|
|
61
|
-
def
|
97
|
+
def generate_topic(rule)
|
62
98
|
"rubocop-challenge/#{rule.title.tr('/', '-')}-#{timestamp}"
|
63
99
|
end
|
64
100
|
|
101
|
+
def pr_template(rule)
|
102
|
+
Github::PrTemplate.new(rule).generate_pullrequest_markdown
|
103
|
+
end
|
104
|
+
|
65
105
|
def timestamp
|
66
106
|
Time.now.strftime('%Y%m%d%H%M%S')
|
67
107
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubocopChallenger
|
4
|
+
module Github
|
5
|
+
class PrTemplate
|
6
|
+
def initialize(rule, template_path = nil)
|
7
|
+
template_path ||= './lib/templates/default.md.erb'
|
8
|
+
@template = File.read(template_path)
|
9
|
+
@rule = rule
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_pullrequest_markdown
|
13
|
+
<<~TEMPLATE
|
14
|
+
#{ERB.new(template, nil, '-').result(binding)}
|
15
|
+
Auto generated by [rubocop_challenger](https://github.com/ryz310/rubocop_challenger)
|
16
|
+
TEMPLATE
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_reader :template, :rule
|
22
|
+
|
23
|
+
def title
|
24
|
+
rule.title
|
25
|
+
end
|
26
|
+
|
27
|
+
def rubydoc_url
|
28
|
+
rule.rubydoc_url
|
29
|
+
end
|
30
|
+
|
31
|
+
def description
|
32
|
+
rule.description
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop_challenger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryosuke_sato
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pr-daikou
|
@@ -147,14 +147,18 @@ files:
|
|
147
147
|
- bin/setup
|
148
148
|
- challenger.gemspec
|
149
149
|
- exe/rubocop_challenger
|
150
|
+
- images/circleci_environment_variables.png
|
151
|
+
- images/generate_token.png
|
150
152
|
- lib/rubocop_challenger.rb
|
151
153
|
- lib/rubocop_challenger/cli.rb
|
154
|
+
- lib/rubocop_challenger/github/pr_template.rb
|
152
155
|
- lib/rubocop_challenger/rubocop/challenge.rb
|
153
156
|
- lib/rubocop_challenger/rubocop/command.rb
|
154
157
|
- lib/rubocop_challenger/rubocop/rule.rb
|
155
158
|
- lib/rubocop_challenger/rubocop/todo_reader.rb
|
156
159
|
- lib/rubocop_challenger/rubocop/todo_writer.rb
|
157
160
|
- lib/rubocop_challenger/version.rb
|
161
|
+
- lib/templates/default.md.erb
|
158
162
|
homepage: https://github.com/ryz310/rubocop_challenger
|
159
163
|
licenses:
|
160
164
|
- MIT
|