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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c793807b7c62bf1aa08436ec4d4de3630a00825e239d8c5d6122f94651b7dd1
4
- data.tar.gz: 50d56cc0b7da03c6f66d6aa93b6e5e814f0b6061997f727b8393bbc85487cc02
3
+ metadata.gz: 8ba8deecbf49b350474a9144e4a1bf8f31d50d287e5dd51f0c3685ad01f86c17
4
+ data.tar.gz: 4c8eef6d0c2d989a8b566b9989364a594f9d874f4c2750096b73dafa8954f6dd
5
5
  SHA512:
6
- metadata.gz: 39ac6e8bb72d0b7a0e941a33dd09a0dd1701c9d59fb3557a7096e0f383c76ee042a29da225bbc80fbc505d2cbfd1e3eced511ef68b90c3a555153ab2f3a85ff1
7
- data.tar.gz: 49f651edd5fd9601ecac5f3fca3914c2f373efd8fab4dcd9df5fdb40328f811b3851644efdc1487a30134427dc2fc029f1904e52a892057007f5c18baece123a
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
- rubocop_challenge_from_gem:
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
- - rubocop_challenge:
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 * * 5" # 8:30am every Saturday (JST)
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
- - rubocop_challenge_from_gem
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-21 01:10:29 +0900 using RuboCop version 0.59.2.
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: 7
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop_challenger (0.1.3)
4
+ rubocop_challenger (0.2.0)
5
5
  pr-daikou (~> 0.2.0)
6
6
  rubocop
7
7
  rubocop-rspec
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
- 2. 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
- 3. You confirm the PR passes testing and then merge it if there is no problem
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
- ## Example
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
- ### Using [CircleCI 2.0](https://circleci.com)
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
+ ![generate token](images/generate_token.png)
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
+ ![circleci environment variables](images/circleci_environment_variables.png)
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
- ## Usage
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 # Pull Request committer email
75
- --name=NAME # Pull Request committer name
76
- f, [--file-path=FILE_PATH] # Set your ".rubocop_todo.yml" path
77
- # Default: .rubocop_todo.yml
78
- [--mode=MODE] # Mode to select deletion target. You can choice "most_occurrence", "least_occurrence", or "random"
79
- # Default: most_occurrence
80
- [--base=BASE] # Base branch of Pull Request
81
- # Default: master
82
- l, [--labels=one two three] # Label to give to Pull Request
83
- # Default: ["rubocop challenge"]
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
@@ -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 = Rubocop::Challenge.exec(options[:file_path], options[:mode])
37
- PRDaikou.exec(pr_daikou_options(target_rule), nil)
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 pr_daikou_options(target_rule)
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: options[:email],
52
- name: options[:name],
53
- base: options[:base],
54
- title: target_rule.title,
55
- labels: options[:labels].join(','),
56
- topic: topic(target_rule),
57
- commit: ":robot: #{target_rule.title}"
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 topic(rule)
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
@@ -6,6 +6,10 @@ module RubocopChallenger
6
6
  def auto_correct
7
7
  `rubocop --auto-correct || true`
8
8
  end
9
+
10
+ def auto_gen_config
11
+ `rubocop --auto-gen-config || true`
12
+ end
9
13
  end
10
14
  end
11
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopChallenger
4
- VERSION = '0.1.3'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,6 @@
1
+ Rubocop challenge!
2
+ [<%= title %>](<%= rubydoc_url %>)
3
+
4
+ <% description.each_line do |line| -%>
5
+ > <%= line.chomp %>
6
+ <% 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.1.3
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-20 00:00:00.000000000 Z
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