rubocop_challenger 2.0.0.pre4 → 2.0.0.pre5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 036a98418d15e70500e3d367abda85fd4ebdfcc1a62026d71388043f691afcc4
4
- data.tar.gz: 10699bfb6619de26f91d767a58f5998e9d0ed3d9fc00be3be849adb20d37b512
3
+ metadata.gz: b7d1fa4268fdf70c18f0d5e2f0529e40f44932af9722c8b5d3d602711255fcb6
4
+ data.tar.gz: 3b1fce68b3d66ccfc0c504eccc608f5f02b41d731f027abe97fb78e07c8563ab
5
5
  SHA512:
6
- metadata.gz: a8b3eba01b0794ede0a9c286f022bf9c5060f26d94da1033406165c88b4445c99cfd8231447f5888110671314c3a35bf2d6c454c21920b0287c9fc17e9ac03c6
7
- data.tar.gz: 657dba914ff64870f44291cacdebd178ddd80ac9e76c6932a2c3dbb2dedbba39597e7e202858ae0737ca8e4843ce26fb8495ae3afe51dd9264a1fd7399678b6a
6
+ metadata.gz: 229ca155ff15eabf0c94e00645a06ef3d443573952982e623fcb9dec475ace6353dddc0f328c2717d7f856762d942e4bb9225d4e9721647527c2c6365a68e834
7
+ data.tar.gz: abfb7b4136efe1f930fd3c87aaa9f08ad7f3cdeb7375def8d38e8c4571de9cf22584f486bcbe5f355a35adec37611499c3d58d28e5c04d736fa5bb7e0937a9c8
data/.rubocop.yml CHANGED
@@ -7,6 +7,7 @@ AllCops:
7
7
 
8
8
  Metrics/BlockLength:
9
9
  Exclude:
10
+ - 'challenger.gemspec'
10
11
  - 'spec/**/*'
11
12
 
12
13
  # For integration testing
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-06-10 12:04:42 +0900 using RuboCop version 0.71.0.
3
+ # on 2019-06-13 12:10:32 +0900 using RuboCop version 0.71.0.
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
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop_challenger (2.0.0.pre4)
5
- pr_comet (~> 0.1.0)
4
+ rubocop_challenger (2.0.0.pre5)
5
+ pr_comet (~> 0.2.0)
6
+ rainbow
6
7
  rubocop
7
8
  rubocop-rspec
8
9
  thor
@@ -17,7 +18,7 @@ GEM
17
18
  byebug (11.0.1)
18
19
  coderay (1.1.2)
19
20
  diff-lcs (1.3)
20
- docile (1.3.1)
21
+ docile (1.3.2)
21
22
  faraday (0.15.4)
22
23
  multipart-post (>= 1.2, < 3)
23
24
  jaro_winkler (1.5.2)
@@ -29,8 +30,9 @@ GEM
29
30
  parallel (1.17.0)
30
31
  parser (2.6.3.0)
31
32
  ast (~> 2.4.0)
32
- pr_comet (0.1.1)
33
+ pr_comet (0.2.0)
33
34
  octokit
35
+ rainbow
34
36
  pry (0.12.2)
35
37
  coderay (~> 1.1.0)
36
38
  method_source (~> 0.9.0)
@@ -46,13 +48,13 @@ GEM
46
48
  rspec-mocks (~> 3.8.0)
47
49
  rspec-core (3.8.0)
48
50
  rspec-support (~> 3.8.0)
49
- rspec-expectations (3.8.3)
51
+ rspec-expectations (3.8.4)
50
52
  diff-lcs (>= 1.2.0, < 2.0)
51
53
  rspec-support (~> 3.8.0)
52
54
  rspec-mocks (3.8.0)
53
55
  diff-lcs (>= 1.2.0, < 2.0)
54
56
  rspec-support (~> 3.8.0)
55
- rspec-support (3.8.0)
57
+ rspec-support (3.8.2)
56
58
  rspec_junit_formatter (0.4.1)
57
59
  rspec-core (>= 2, < 4, != 2.12.0)
58
60
  rubocop (0.71.0)
data/README.md CHANGED
@@ -109,16 +109,19 @@ Usage:
109
109
  rubocop_challenger go --email=EMAIL --name=NAME
110
110
 
111
111
  Options:
112
- --email=EMAIL # The Pull Request committer email
113
- --name=NAME # The Pull Request committer name
114
- f, [--file-path=FILE_PATH] # Set your ".rubocop_todo.yml" path
115
- # Default: .rubocop_todo.yml
116
- t, [--template=TEMPLATE] # A Pull Request template `erb` file path.You can use variable that `title`, `rubydoc_url`, `description` and `examples` into the erb file.
117
- [--mode=MODE] # Mode to select deletion target. You can choice "most_occurrence", "least_occurrence", or "random"
118
- # Default: most_occurrence
119
- l, [--labels=one two three] # Label to give to Pull Request
120
- # Default: ["rubocop challenge"]
121
- [--no-create-pr] # No create a pull request (for testing)
112
+ --email=EMAIL # The Pull Request committer email
113
+ --name=NAME # The Pull Request committer name
114
+ f, [--file-path=FILE_PATH] # Set your ".rubocop_todo.yml" path
115
+ # Default: .rubocop_todo.yml
116
+ t, [--template=TEMPLATE] # A Pull Request template `erb` file path.You can use variable that `title`, `rubydoc_url`, `description` and `examples` into the erb file.
117
+ [--mode=MODE] # Mode to select deletion target. You can choice "most_occurrence", "least_occurrence", or "random"
118
+ # Default: most_occurrence
119
+ l, [--labels=one two three] # Label to give to Pull Request
120
+ # Default: ["rubocop challenge"]
121
+ [--no-create-pr] # No create a pull request (for testing)
122
+ [--exclude-limit=N] # For how many exclude properties when creating the .rubocop_todo.yml
123
+ [--auto-gen-timestamp], [--no-auto-gen-timestamp] # Include the date and time when creating the .rubocop_todo.yml
124
+ # Default: true
122
125
 
123
126
  Run `$ rubocop --auto-correct` and create a PR to GitHub repo
124
127
  ```
data/challenger.gemspec CHANGED
@@ -22,7 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_runtime_dependency 'pr_comet', '~> 0.1.0'
25
+ spec.add_runtime_dependency 'pr_comet', '~> 0.2.0'
26
+ spec.add_runtime_dependency 'rainbow'
26
27
  spec.add_runtime_dependency 'rubocop'
27
28
  spec.add_runtime_dependency 'rubocop-rspec'
28
29
  spec.add_runtime_dependency 'thor'
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'erb'
4
4
  require 'yard'
5
+ require 'rainbow'
5
6
  require 'pr_comet'
6
7
  require 'rubocop'
7
8
  require 'rubocop-rspec'
@@ -6,10 +6,16 @@ module RubocopChallenger
6
6
  class Command
7
7
  include PrComet::CommandLine
8
8
 
9
+ # Executes `$ bundle update` which excludes not installed gems
10
+ #
11
+ # @param gem_names [Array<String>] The target gem names
9
12
  def update(*gem_names)
10
- run('update', *gem_names)
13
+ run('update', *gem_names.select(&method(:installed?)))
11
14
  end
12
15
 
16
+ # Checks the gem is installed
17
+ #
18
+ # @return [Boolean] Returns true if installed
13
19
  def installed?(gem_name)
14
20
  !run('list', '|', 'grep', gem_name).empty?
15
21
  end
@@ -5,8 +5,6 @@ require 'thor'
5
5
  module RubocopChallenger
6
6
  # To define CLI commands
7
7
  class CLI < Thor
8
- include PrComet::CommandLine
9
-
10
8
  desc 'go', 'Run `$ rubocop --auto-correct` and create a PR to GitHub repo'
11
9
  option :email,
12
10
  required: true,
@@ -37,16 +35,33 @@ module RubocopChallenger
37
35
  default: ['rubocop challenge'],
38
36
  aliases: :l,
39
37
  desc: 'Label to give to Pull Request'
38
+ option :project_column_name,
39
+ type: :string,
40
+ desc: 'A project column name. You can add the created PR to the ' \
41
+ 'GitHub project'
42
+ option :project_id,
43
+ type: :numeric,
44
+ desc: 'A target project ID. If does not supplied, this method ' \
45
+ 'will find a project which associated the repository. When ' \
46
+ 'the repository has multiple projects, you should supply this.'
40
47
  option :'no-create-pr',
41
48
  type: :boolean,
42
49
  default: false,
43
50
  desc: 'No create a pull request (for testing)'
51
+ option :'exclude-limit',
52
+ type: :numeric,
53
+ desc: 'For how many exclude properties when creating the ' \
54
+ '.rubocop_todo.yml'
55
+ option :'auto-gen-timestamp',
56
+ type: :boolean,
57
+ default: true,
58
+ desc: 'Include the date and time when creating the .rubocop_todo.yml'
44
59
  def go
45
60
  Go.new(options).exec
46
61
  rescue Errors::NoAutoCorrectableRule => e
47
- color_puts e.message, PrComet::CommandLine::YELLOW
62
+ puts Rainbow(e.message).yellow
48
63
  rescue StandardError => e
49
- color_puts e.message, PrComet::CommandLine::RED
64
+ puts Rainbow(e.message).red
50
65
  exit_process!
51
66
  end
52
67
 
@@ -3,17 +3,31 @@
3
3
  module RubocopChallenger
4
4
  # Executes Rubocop Challenge flow
5
5
  class Go
6
- include PrComet::CommandLine
7
-
8
- # @param options [Hash] describe_options_here
6
+ # @param options [Hash]
7
+ # Options for the rubocop challenge
8
+ # @option exclude-limit [Integer]
9
+ # For how many exclude properties when creating the ".rubocop_todo.yml"
10
+ # @option auto-gen-timestamp [Boolean]
11
+ # Include the date and time when creating the ".rubocop_todo.yml"
12
+ # @option name [String]
13
+ # The author name which use at the git commit
14
+ # @option email [String]
15
+ # The email address which use at the git commit
16
+ # @option labels [Array<String>]
17
+ # Will create a pull request with the labels
18
+ # @option no-create-pr [Boolean]
19
+ # Does not create a pull request when given `true`
20
+ # @option project_column_name [String]
21
+ # A project column name. You can add the created PR to the GitHub project
22
+ # @option project_id [Integer]
23
+ # A target project ID. If does not supplied, this method will find a
24
+ # project which associated the repository. When the repository has
25
+ # multiple projects, you should supply this.
9
26
  def initialize(options)
10
27
  @options = options
11
- @pull_request = PullRequest.new(
12
- options[:name],
13
- options[:email],
14
- options[:labels],
15
- options[:'no-create-pr']
16
- )
28
+ @exclude_limit = options[:'exclude-limit']
29
+ @auto_gen_timestamp = options[:'auto-gen-timestamp']
30
+ @pull_request = PullRequest.new(extract_pull_request_options(options))
17
31
  end
18
32
 
19
33
  # Executes Rubocop Challenge flow
@@ -31,13 +45,31 @@ module RubocopChallenger
31
45
 
32
46
  private
33
47
 
34
- attr_reader :options, :pull_request
48
+ attr_reader :options, :pull_request, :exclude_limit, :auto_gen_timestamp
49
+
50
+ # Extracts options for the PullRequest class
51
+ #
52
+ # @param options [Hash] The target options
53
+ # @return [Hash] Options for the PullRequest class
54
+ def extract_pull_request_options(options)
55
+ {
56
+ user_name: options[:name],
57
+ user_email: options[:email],
58
+ labels: options[:labels],
59
+ dry_run: options[:'no-create-pr'],
60
+ project_column_name: options[:project_column_name],
61
+ project_id: options[:project_id]
62
+ }
63
+ end
35
64
 
65
+ # Executes `$ bundle update` for the rubocop and the associated gems
36
66
  def update_rubocop!
37
67
  bundler = Bundler::Command.new
38
68
  pull_request.commit! ':police_car: $ bundle update rubocop' do
39
- bundler.update 'rubocop'
40
- bundler.update 'rubocop-rspec' if bundler.installed?('rubocop-rspec')
69
+ bundler.update 'rubocop',
70
+ 'rubocop-performance',
71
+ 'rubocop-rails',
72
+ 'rubocop-rspec'
41
73
  end
42
74
  end
43
75
 
@@ -49,7 +81,10 @@ module RubocopChallenger
49
81
  def regenerate_rubocop_todo!
50
82
  before_version = scan_rubocop_version_in_rubocop_todo_file
51
83
  pull_request.commit! ':police_car: regenerate rubocop todo' do
52
- Rubocop::Command.new.auto_gen_config
84
+ Rubocop::Command.new.auto_gen_config(
85
+ exclude_limit: exclude_limit,
86
+ auto_gen_timestamp: auto_gen_timestamp
87
+ )
53
88
  end
54
89
  after_version = scan_rubocop_version_in_rubocop_todo_file
55
90
 
@@ -126,8 +161,7 @@ module RubocopChallenger
126
161
  config_editor.add_ignore(rule)
127
162
  config_editor.save
128
163
  end
129
- color_puts DESCRIPTION_THAT_CHALLENGE_IS_INCOMPLETE,
130
- PrComet::CommandLine::YELLOW
164
+ puts Rainbow(DESCRIPTION_THAT_CHALLENGE_IS_INCOMPLETE).yellow
131
165
  end
132
166
 
133
167
  # Checks the challenge result. If the challenge is successed, the rule
@@ -7,19 +7,29 @@ module RubocopChallenger
7
7
  # The author name which use at the git commit
8
8
  # @param user_email [String]
9
9
  # The email address which use at the git commit
10
- # @param labels [Array<String>]
10
+ # @param options [Hash]
11
+ # Optional parameters
12
+ # @option labels [Array<String>]
11
13
  # Will create a pull request with the labels
12
- # @param dry_run [Boolean]
14
+ # @option dry_run [Boolean]
13
15
  # Does not create a pull request when given `true`
14
- def initialize(user_name, user_email, labels, dry_run = false)
16
+ # @option project_column_name [String]
17
+ # A project column name. You can add the created PR to the GitHub project
18
+ # @option project_id [Integer]
19
+ # A target project ID. If does not supplied, this method will find a
20
+ # project which associated the repository. When the repository has
21
+ # multiple projects, you should supply this.
22
+ def initialize(user_name:, user_email:, **options)
15
23
  @pr_comet = PrComet.new(
16
24
  base: 'master',
17
25
  branch: "rubocop-challenge/#{timestamp}",
18
26
  user_name: user_name,
19
27
  user_email: user_email
20
28
  )
21
- @labels = labels
22
- @dry_run = dry_run
29
+ @labels = options[:labels]
30
+ @dry_run = options[:dry_run]
31
+ @project_column_name = options[:project_column_name]
32
+ @project_id = options[:project_id]
23
33
  end
24
34
 
25
35
  # Add and commit local files to the pull request
@@ -42,8 +52,7 @@ module RubocopChallenger
42
52
  def create_rubocop_challenge_pr!(rule, template_file_path = nil)
43
53
  create_pull_request!(
44
54
  title: "#{rule.title}-#{timestamp}",
45
- body: Github::PrTemplate.new(rule, template_file_path).generate,
46
- labels: labels
55
+ body: Github::PrTemplate.new(rule, template_file_path).generate
47
56
  )
48
57
  end
49
58
 
@@ -61,18 +70,25 @@ module RubocopChallenger
61
70
  def create_regenerate_todo_pr!(before_version, after_version)
62
71
  create_pull_request!(
63
72
  title: "Re-generate .rubocop_todo.yml with RuboCop v#{after_version}",
64
- body: generate_pull_request_body(before_version, after_version),
65
- labels: labels
73
+ body: generate_pull_request_body(before_version, after_version)
66
74
  )
67
75
  end
68
76
 
69
77
  private
70
78
 
71
- attr_reader :pr_comet, :labels, :dry_run
79
+ attr_reader :pr_comet, :labels, :dry_run, :project_column_name, :project_id
72
80
 
73
81
  # Create a PR with description of what modification were made.
82
+ #
83
+ # @params pr_comet_options [Hash]
74
84
  def create_pull_request!(pr_comet_options)
75
- pr_comet.create!(pr_comet_options) unless dry_run
85
+ options = {
86
+ labels: labels,
87
+ project_column_name: project_column_name,
88
+ project_id: project_id
89
+ }.merge(pr_comet_options)
90
+
91
+ pr_comet.create!(options) unless dry_run
76
92
  end
77
93
 
78
94
  # @param before_version [String]
@@ -6,12 +6,20 @@ module RubocopChallenger
6
6
  class Command
7
7
  include PrComet::CommandLine
8
8
 
9
+ # Executes auto correction
9
10
  def auto_correct
10
11
  run('--auto-correct')
11
12
  end
12
13
 
13
- def auto_gen_config
14
- run('--auto-gen-config')
14
+ # Generates `.rubocop_todo.yml`
15
+ #
16
+ # @param exclude_limit [Integer] default: nil
17
+ # @param auto_gen_timestamp [Boolean] default: true
18
+ def auto_gen_config(exclude_limit: nil, auto_gen_timestamp: true)
19
+ commands = ['--auto-gen-config']
20
+ commands << "--exclude-limit #{exclude_limit}" if exclude_limit
21
+ commands << '--no-auto-gen-timestamp' unless auto_gen_timestamp
22
+ run(*commands)
15
23
  end
16
24
 
17
25
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopChallenger
4
- VERSION = '2.0.0.pre4'
4
+ VERSION = '2.0.0.pre5'
5
5
  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: 2.0.0.pre4
4
+ version: 2.0.0.pre5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryosuke_sato
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-10 00:00:00.000000000 Z
11
+ date: 2019-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pr_comet
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rainbow
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rubocop
29
43
  requirement: !ruby/object:Gem::Requirement