rubocop_challenger 2.0.0.pre → 2.0.0.pre2
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/.rubocop_todo.yml +1 -1
- data/Gemfile.lock +9 -7
- data/bin/{create_release_pr → release} +8 -11
- data/challenger.gemspec +1 -1
- data/lib/rubocop_challenger/bundler/command.rb +1 -1
- data/lib/rubocop_challenger/cli.rb +3 -3
- data/lib/rubocop_challenger/errors.rb +0 -2
- data/lib/rubocop_challenger/go.rb +3 -2
- data/lib/rubocop_challenger/pull_request.rb +5 -5
- data/lib/rubocop_challenger/rubocop/command.rb +1 -1
- data/lib/rubocop_challenger/version.rb +1 -1
- data/lib/rubocop_challenger.rb +1 -5
- metadata +4 -8
- data/lib/rubocop_challenger/command_line.rb +0 -30
- data/lib/rubocop_challenger/git/command.rb +0 -98
- data/lib/rubocop_challenger/github/client.rb +0 -42
- data/lib/rubocop_challenger/github/pr_creater.rb +0 -83
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a16dd2ba41bc75373d730d5b92bd0e908a26a9ac8ec5e6ec3732d122f3ca946
|
|
4
|
+
data.tar.gz: ee5feeabc11854d8f5d214dadf4a476dcfd531618f073eca548ce706c82ec215
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33269aaa091dd13c2e7a81a57d89930d16238c494ca07a6307290c125ae57ba160fafcb6abcd84f717231e23ed031d99324570fc245e6360c78b402a9b75b457
|
|
7
|
+
data.tar.gz: d274632af2fa2cc0a9dd9f30527b0e19073d97e06c02d2701a95d8426ebab782d79efd963f8c794aa10ddc828eb5f728cb018e4957a955598a43ef6c1eb23dc3
|
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-
|
|
3
|
+
# on 2019-04-09 22:04:02 +0900 using RuboCop version 0.67.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
|
data/Gemfile.lock
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rubocop_challenger (2.0.0.
|
|
5
|
-
|
|
4
|
+
rubocop_challenger (2.0.0.pre2)
|
|
5
|
+
pr_comet
|
|
6
6
|
rubocop
|
|
7
7
|
rubocop-rspec
|
|
8
8
|
thor
|
|
@@ -26,9 +26,11 @@ GEM
|
|
|
26
26
|
multipart-post (2.0.0)
|
|
27
27
|
octokit (4.14.0)
|
|
28
28
|
sawyer (~> 0.8.0, >= 0.5.3)
|
|
29
|
-
parallel (1.
|
|
30
|
-
parser (2.6.2.
|
|
29
|
+
parallel (1.17.0)
|
|
30
|
+
parser (2.6.2.1)
|
|
31
31
|
ast (~> 2.4.0)
|
|
32
|
+
pr_comet (0.1.1)
|
|
33
|
+
octokit
|
|
32
34
|
pry (0.12.2)
|
|
33
35
|
coderay (~> 1.1.0)
|
|
34
36
|
method_source (~> 0.9.0)
|
|
@@ -54,7 +56,7 @@ GEM
|
|
|
54
56
|
rspec-support (3.8.0)
|
|
55
57
|
rspec_junit_formatter (0.4.1)
|
|
56
58
|
rspec-core (>= 2, < 4, != 2.12.0)
|
|
57
|
-
rubocop (0.
|
|
59
|
+
rubocop (0.67.2)
|
|
58
60
|
jaro_winkler (~> 1.5.1)
|
|
59
61
|
parallel (~> 1.10)
|
|
60
62
|
parser (>= 2.5, != 2.5.1.1)
|
|
@@ -75,7 +77,7 @@ GEM
|
|
|
75
77
|
simplecov-html (0.10.2)
|
|
76
78
|
thor (0.20.3)
|
|
77
79
|
unicode-display_width (1.5.0)
|
|
78
|
-
yard (0.9.
|
|
80
|
+
yard (0.9.19)
|
|
79
81
|
|
|
80
82
|
PLATFORMS
|
|
81
83
|
ruby
|
|
@@ -90,4 +92,4 @@ DEPENDENCIES
|
|
|
90
92
|
simplecov
|
|
91
93
|
|
|
92
94
|
BUNDLED WITH
|
|
93
|
-
1.
|
|
95
|
+
1.17.3
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
# usage: bin/
|
|
4
|
+
# usage: bin/release VERSION
|
|
5
5
|
|
|
6
6
|
require 'bundler/setup'
|
|
7
7
|
require 'rubocop_challenger'
|
|
@@ -9,17 +9,14 @@ require 'rubocop_challenger'
|
|
|
9
9
|
VERSION_FORMAT = /\A\d+\.\d+\.\d+(\.(pre|beta|rc)\d?)?\z/.freeze
|
|
10
10
|
version = ARGV[0]
|
|
11
11
|
rubocop = RubocopChallenger::Rubocop::Command.new
|
|
12
|
-
|
|
13
|
-
RubocopChallenger::Github::PrCreater.new(
|
|
14
|
-
base: 'master', branch: "update/v#{version}"
|
|
15
|
-
)
|
|
12
|
+
pr_comet = PrComet.new(base: 'master', branch: "update/v#{version}")
|
|
16
13
|
|
|
17
14
|
# Verifying
|
|
18
|
-
abort 'usage: bin/
|
|
15
|
+
abort 'usage: bin/release VERSION' if version.nil?
|
|
19
16
|
abort 'A version must be like a `1.2.3`' unless version =~ VERSION_FORMAT
|
|
20
17
|
|
|
21
18
|
# Modify a version file
|
|
22
|
-
|
|
19
|
+
pr_comet.commit 'Update version' do
|
|
23
20
|
File.write('lib/rubocop_challenger/version.rb', <<~VERSION)
|
|
24
21
|
# frozen_string_literal: true
|
|
25
22
|
|
|
@@ -30,14 +27,14 @@ pr_creater.commit 'Update version' do
|
|
|
30
27
|
end
|
|
31
28
|
|
|
32
29
|
# Bundle Update
|
|
33
|
-
|
|
30
|
+
pr_comet.commit 'Run $ bundle update' do
|
|
34
31
|
`bundle update`
|
|
35
32
|
end
|
|
36
33
|
|
|
37
34
|
# Regenerate .rubocop_todo.yml
|
|
38
|
-
|
|
35
|
+
pr_comet.commit 'Regenerate .rubocop_todo.yml' do
|
|
39
36
|
rubocop.auto_gen_config
|
|
40
37
|
end
|
|
41
38
|
|
|
42
|
-
# Create
|
|
43
|
-
|
|
39
|
+
# Create a pull request
|
|
40
|
+
pr_comet.create!(title: "Update v#{version}", body: '')
|
data/challenger.gemspec
CHANGED
|
@@ -22,7 +22,7 @@ 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 '
|
|
25
|
+
spec.add_runtime_dependency 'pr_comet'
|
|
26
26
|
spec.add_runtime_dependency 'rubocop'
|
|
27
27
|
spec.add_runtime_dependency 'rubocop-rspec'
|
|
28
28
|
spec.add_runtime_dependency 'thor'
|
|
@@ -5,7 +5,7 @@ require 'thor'
|
|
|
5
5
|
module RubocopChallenger
|
|
6
6
|
# To define CLI commands
|
|
7
7
|
class CLI < Thor
|
|
8
|
-
include CommandLine
|
|
8
|
+
include PrComet::CommandLine
|
|
9
9
|
|
|
10
10
|
desc 'go', 'Run `$ rubocop --auto-correct` and create a PR to GitHub repo'
|
|
11
11
|
option :email,
|
|
@@ -44,9 +44,9 @@ module RubocopChallenger
|
|
|
44
44
|
def go
|
|
45
45
|
Go.new(options).exec
|
|
46
46
|
rescue Errors::NoAutoCorrectableRule => e
|
|
47
|
-
color_puts e.message, CommandLine::YELLOW
|
|
47
|
+
color_puts e.message, PrComet::CommandLine::YELLOW
|
|
48
48
|
rescue StandardError => e
|
|
49
|
-
color_puts e.message, CommandLine::RED
|
|
49
|
+
color_puts e.message, PrComet::CommandLine::RED
|
|
50
50
|
exit_process!
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module RubocopChallenger
|
|
4
4
|
# Executes Rubocop Challenge flow
|
|
5
5
|
class Go
|
|
6
|
-
include CommandLine
|
|
6
|
+
include PrComet::CommandLine
|
|
7
7
|
|
|
8
8
|
# @param options [Hash] describe_options_here
|
|
9
9
|
def initialize(options)
|
|
@@ -126,7 +126,8 @@ module RubocopChallenger
|
|
|
126
126
|
config_editor.add_ignore(rule)
|
|
127
127
|
config_editor.save
|
|
128
128
|
end
|
|
129
|
-
color_puts DESCRIPTION_THAT_CHALLENGE_IS_INCOMPLETE,
|
|
129
|
+
color_puts DESCRIPTION_THAT_CHALLENGE_IS_INCOMPLETE,
|
|
130
|
+
PrComet::CommandLine::YELLOW
|
|
130
131
|
end
|
|
131
132
|
|
|
132
133
|
# Checks the challenge result. If the challenge is successed, the rule
|
|
@@ -12,7 +12,7 @@ module RubocopChallenger
|
|
|
12
12
|
# @param dry_run [Boolean]
|
|
13
13
|
# Does not create a pull request when given `true`
|
|
14
14
|
def initialize(user_name, user_email, labels, dry_run = false)
|
|
15
|
-
@
|
|
15
|
+
@pr_comet = PrComet.new(
|
|
16
16
|
base: 'master',
|
|
17
17
|
branch: "rubocop-challenge/#{timestamp}",
|
|
18
18
|
user_name: user_name,
|
|
@@ -28,7 +28,7 @@ module RubocopChallenger
|
|
|
28
28
|
# @yield Some commands where modify local files
|
|
29
29
|
# @return [Object] Return result of yield if you use &block
|
|
30
30
|
def commit!(message, &block)
|
|
31
|
-
|
|
31
|
+
pr_comet.commit message, &block
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
# Creates a pull request for the Rubocop Challenge
|
|
@@ -68,11 +68,11 @@ module RubocopChallenger
|
|
|
68
68
|
|
|
69
69
|
private
|
|
70
70
|
|
|
71
|
-
attr_reader :
|
|
71
|
+
attr_reader :pr_comet, :labels, :dry_run
|
|
72
72
|
|
|
73
73
|
# Create a PR with description of what modification were made.
|
|
74
|
-
def create_pull_request!(
|
|
75
|
-
|
|
74
|
+
def create_pull_request!(pr_comet_options)
|
|
75
|
+
pr_comet.create!(pr_comet_options) unless dry_run
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def generate_pull_request_body(before_version, after_version)
|
data/lib/rubocop_challenger.rb
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
require 'erb'
|
|
4
4
|
require 'yard'
|
|
5
|
-
require '
|
|
5
|
+
require 'pr_comet'
|
|
6
6
|
require 'rubocop'
|
|
7
7
|
require 'rubocop-rspec'
|
|
8
8
|
require 'rubocop_challenger/errors'
|
|
9
9
|
require 'rubocop_challenger/version'
|
|
10
|
-
require 'rubocop_challenger/command_line'
|
|
11
10
|
require 'rubocop_challenger/rubocop/rule'
|
|
12
11
|
require 'rubocop_challenger/rubocop/config_editor'
|
|
13
12
|
require 'rubocop_challenger/rubocop/todo_reader'
|
|
@@ -19,7 +18,4 @@ require 'rubocop_challenger/pull_request'
|
|
|
19
18
|
require 'rubocop_challenger/go'
|
|
20
19
|
require 'rubocop_challenger/cli'
|
|
21
20
|
require 'rubocop_challenger/bundler/command'
|
|
22
|
-
require 'rubocop_challenger/git/command'
|
|
23
|
-
require 'rubocop_challenger/github/client'
|
|
24
21
|
require 'rubocop_challenger/github/pr_template'
|
|
25
|
-
require 'rubocop_challenger/github/pr_creater'
|
metadata
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop_challenger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.0.
|
|
4
|
+
version: 2.0.0.pre2
|
|
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-
|
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: pr_comet
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
@@ -185,8 +185,8 @@ files:
|
|
|
185
185
|
- README.md
|
|
186
186
|
- Rakefile
|
|
187
187
|
- bin/console
|
|
188
|
-
- bin/create_release_pr
|
|
189
188
|
- bin/jailbreak
|
|
189
|
+
- bin/release
|
|
190
190
|
- bin/setup
|
|
191
191
|
- challenger.gemspec
|
|
192
192
|
- exe/rubocop_challenger
|
|
@@ -196,11 +196,7 @@ files:
|
|
|
196
196
|
- lib/rubocop_challenger.rb
|
|
197
197
|
- lib/rubocop_challenger/bundler/command.rb
|
|
198
198
|
- lib/rubocop_challenger/cli.rb
|
|
199
|
-
- lib/rubocop_challenger/command_line.rb
|
|
200
199
|
- lib/rubocop_challenger/errors.rb
|
|
201
|
-
- lib/rubocop_challenger/git/command.rb
|
|
202
|
-
- lib/rubocop_challenger/github/client.rb
|
|
203
|
-
- lib/rubocop_challenger/github/pr_creater.rb
|
|
204
200
|
- lib/rubocop_challenger/github/pr_template.rb
|
|
205
201
|
- lib/rubocop_challenger/go.rb
|
|
206
202
|
- lib/rubocop_challenger/pull_request.rb
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module RubocopChallenger
|
|
4
|
-
# To execute command line. You should inherit this class to use.
|
|
5
|
-
module CommandLine
|
|
6
|
-
private
|
|
7
|
-
|
|
8
|
-
# Execute a command
|
|
9
|
-
#
|
|
10
|
-
# @param command [String] The command you want to execute
|
|
11
|
-
# @return [String] The result in the execution
|
|
12
|
-
def execute(command)
|
|
13
|
-
puts "$ #{command}"
|
|
14
|
-
`#{command}`.chomp.tap do |result|
|
|
15
|
-
color_code = $CHILD_STATUS.success? ? GREEN : RED
|
|
16
|
-
color_puts(result, color_code)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
RED = 31
|
|
21
|
-
GREEN = 32
|
|
22
|
-
YELLOW = 33
|
|
23
|
-
BLUE = 34
|
|
24
|
-
PING = 35
|
|
25
|
-
|
|
26
|
-
def color_puts(string, color_code)
|
|
27
|
-
puts "\e[#{color_code}m#{string}\e[0m"
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module RubocopChallenger
|
|
4
|
-
module Git
|
|
5
|
-
# To execute git command
|
|
6
|
-
class Command
|
|
7
|
-
include CommandLine
|
|
8
|
-
|
|
9
|
-
def initialize(user_name: nil, user_email: nil)
|
|
10
|
-
@user_name = user_name
|
|
11
|
-
@user_email = user_email
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def user_name
|
|
15
|
-
@user_name ||= config('user.name')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def user_email
|
|
19
|
-
@user_email ||= config('user.email')
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def exist_uncommitted_modify?
|
|
23
|
-
execute('git add -n .; git diff --name-only') != ''
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def checkout(branch)
|
|
27
|
-
run('checkout', branch)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def checkout_with(new_branch)
|
|
31
|
-
run('checkout', '-b', new_branch)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def add(*files)
|
|
35
|
-
run('add', *files)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def commit(message)
|
|
39
|
-
run_with_environments('commit', '-m', "\"#{message}\"")
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Execute git push command
|
|
43
|
-
#
|
|
44
|
-
# @note For security, this command add a quiet option automatically.
|
|
45
|
-
# @param remote [String] The remote repository name.
|
|
46
|
-
# @param branch [String] The target branch. default: `#current_branch`
|
|
47
|
-
# @return [String] The command's standard output.
|
|
48
|
-
def push(remote, branch = current_branch)
|
|
49
|
-
run('push', '-q', remote, branch)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def current_sha1
|
|
53
|
-
run('rev-parse', 'HEAD')
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def current_sha1?(sha1)
|
|
57
|
-
current_sha1 == sha1.to_s
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def current_branch
|
|
61
|
-
run('rev-parse', '--abbrev-ref', 'HEAD')
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def current_branch?(branch)
|
|
65
|
-
current_branch == branch.to_s
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def remote_url(remote)
|
|
69
|
-
config("--get remote.#{remote}.url")
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
private
|
|
73
|
-
|
|
74
|
-
def run(*subcommands)
|
|
75
|
-
command = "git #{subcommands.join(' ')}"
|
|
76
|
-
execute(command)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def run_with_environments(*subcommands)
|
|
80
|
-
command = "#{environments} git #{subcommands.join(' ')}"
|
|
81
|
-
execute(command)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def config(key)
|
|
85
|
-
run('config', key)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def environments
|
|
89
|
-
@environments ||= [
|
|
90
|
-
"GIT_AUTHOR_NAME=\"#{user_name}\"",
|
|
91
|
-
"GIT_AUTHOR_EMAIL=\"#{user_email}\"",
|
|
92
|
-
"GIT_COMMITTER_NAME=\"#{user_name}\"",
|
|
93
|
-
"GIT_COMMITTER_EMAIL=\"#{user_email}\""
|
|
94
|
-
].join(' ')
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module RubocopChallenger
|
|
4
|
-
module Github
|
|
5
|
-
# GitHub API Client
|
|
6
|
-
class Client
|
|
7
|
-
attr_reader :repository
|
|
8
|
-
|
|
9
|
-
def initialize(access_token, remote_url)
|
|
10
|
-
@client = Octokit::Client.new(access_token: access_token)
|
|
11
|
-
@repository = remote_url.match(REPOSITORY_MATCHER)[:repository]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Create a pull request
|
|
15
|
-
#
|
|
16
|
-
# @param base [String] The branch you want your changes pulled into
|
|
17
|
-
# @param head [String] The branch where your changes are implemented
|
|
18
|
-
# @param title [String] Title for the pull request
|
|
19
|
-
# @param body [String] The body for the pull request
|
|
20
|
-
# @return [Integer] Created pull request number
|
|
21
|
-
def create_pull_request(base:, head:, title:, body:)
|
|
22
|
-
response =
|
|
23
|
-
client.create_pull_request(repository, base, head, title, body)
|
|
24
|
-
response.number
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Description of #add_labels
|
|
28
|
-
#
|
|
29
|
-
# @param issue_number [Integer] Number ID of the issue (or pull request)
|
|
30
|
-
# @param labels [Array<String>] An array of labels to apply to this Issue
|
|
31
|
-
def add_labels(issue_number, *labels)
|
|
32
|
-
client.add_labels_to_an_issue(repository, issue_number, labels)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
REPOSITORY_MATCHER = %r{github\.com[:/](?<repository>.+)\.git}.freeze
|
|
38
|
-
|
|
39
|
-
attr_reader :client
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module RubocopChallenger
|
|
4
|
-
module Github
|
|
5
|
-
# To create Pull Request
|
|
6
|
-
class PrCreater
|
|
7
|
-
# Returns a new instance of Github::PrCreater
|
|
8
|
-
#
|
|
9
|
-
# @note You have to set ENV['GITHUB_ACCESS_TOKEN']
|
|
10
|
-
# @param base [String] The branch you want your changes pulled into
|
|
11
|
-
# @param branch [String] The branch where your changes are going to
|
|
12
|
-
# implement.
|
|
13
|
-
# @param user_name [String] The username to use for committer and author
|
|
14
|
-
# @param user_email [String] The email to use for committer and author
|
|
15
|
-
def initialize(base:, branch:, user_name: nil, user_email: nil)
|
|
16
|
-
raise "You have to set ENV['GITHUB_ACCESS_TOKEN']" if access_token.nil?
|
|
17
|
-
|
|
18
|
-
@base_branch = base
|
|
19
|
-
@topic_branch = branch
|
|
20
|
-
@git = Git::Command.new(user_name: user_name, user_email: user_email)
|
|
21
|
-
@github = Github::Client.new(access_token, git.remote_url('origin'))
|
|
22
|
-
@initial_sha1 = git.current_sha1
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Add and commit local files to this branch
|
|
26
|
-
#
|
|
27
|
-
# @param message [String] The commit message
|
|
28
|
-
# @yield Some commands where modify local files
|
|
29
|
-
# @return [Object] Return result of yield if you use &block
|
|
30
|
-
# @raise [RubocopChallenger::Errors::ExistUncommittedModify]
|
|
31
|
-
# Raise error if you use &block and exists someuncommitted files
|
|
32
|
-
def commit(message, &block)
|
|
33
|
-
git.checkout_with(topic_branch) unless git.current_branch?(topic_branch)
|
|
34
|
-
result = modify_files(&block) if block_given?
|
|
35
|
-
git.add('.')
|
|
36
|
-
git.commit(message)
|
|
37
|
-
result
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Create a pull request
|
|
41
|
-
# You should call #commit before calling this method
|
|
42
|
-
#
|
|
43
|
-
# @param title [String] Title for the pull request
|
|
44
|
-
# @param body [String] The body for the pull request
|
|
45
|
-
# @param labels [Array<String>] An array of labels to apply to this PR
|
|
46
|
-
# @return [Boolean] Return true if its successed
|
|
47
|
-
def create_pr(title:, body:, labels: nil)
|
|
48
|
-
return false unless git_condition_valid?
|
|
49
|
-
|
|
50
|
-
git.push(github_token_url, topic_branch)
|
|
51
|
-
pr_number = github.create_pull_request(
|
|
52
|
-
base: base_branch, head: topic_branch, title: title, body: body
|
|
53
|
-
)
|
|
54
|
-
github.add_labels(pr_number, *labels) unless labels.nil?
|
|
55
|
-
true
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
private
|
|
59
|
-
|
|
60
|
-
attr_reader :git, :github, :base_branch, :topic_branch, :initial_sha1
|
|
61
|
-
|
|
62
|
-
def git_condition_valid?
|
|
63
|
-
!git.current_sha1?(initial_sha1) && git.current_branch?(topic_branch)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def modify_files
|
|
67
|
-
raise Errors::ExistUncommittedModify if git.exist_uncommitted_modify?
|
|
68
|
-
|
|
69
|
-
yield
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def access_token
|
|
73
|
-
ENV['GITHUB_ACCESS_TOKEN']
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# @note You *MUST NOT* use `#access_token` in the URL because this string
|
|
77
|
-
# will be output STDOUT via `RubocopChallenger::CommandLine` module.
|
|
78
|
-
def github_token_url
|
|
79
|
-
"https://${GITHUB_ACCESS_TOKEN}@github.com/#{github.repository}"
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|