git_reflow 0.7.5 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Appraisals +2 -2
- data/CHANGELOG.md +75 -0
- data/Gemfile.lock +34 -35
- data/README.rdoc +187 -60
- data/circle.yml +9 -9
- data/git_reflow.gemspec +8 -8
- data/lib/git_reflow/commands/deliver.rb +1 -9
- data/lib/git_reflow/commands/refresh.rb +23 -0
- data/lib/git_reflow/commands/review.rb +7 -7
- data/lib/git_reflow/commands/setup.rb +7 -3
- data/lib/git_reflow/commands/start.rb +13 -5
- data/lib/git_reflow/git_helpers.rb +22 -23
- data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +4 -4
- data/lib/git_reflow/git_server/bit_bucket.rb +7 -7
- data/lib/git_reflow/git_server/git_hub/pull_request.rb +75 -2
- data/lib/git_reflow/git_server/git_hub.rb +17 -8
- data/lib/git_reflow/git_server/pull_request.rb +73 -5
- data/lib/git_reflow/git_server.rb +3 -3
- data/lib/git_reflow/merge_error.rb +9 -0
- data/lib/git_reflow/sandbox.rb +4 -16
- data/lib/git_reflow/version.rb +1 -1
- data/lib/git_reflow.rb +32 -75
- data/spec/git_reflow_spec.rb +157 -141
- data/spec/lgtm_git_reflow_spec.rb +165 -139
- data/spec/lib/git_reflow/git_helpers_spec.rb +19 -63
- data/spec/lib/git_reflow/git_server_spec.rb +24 -24
- data/spec/lib/git_server/bit_bucket_spec.rb +12 -12
- data/spec/lib/git_server/git_hub/pull_request_spec.rb +7 -5
- data/spec/lib/git_server/git_hub_spec.rb +34 -34
- data/spec/lib/git_server/pull_request_spec.rb +207 -16
- data/spec/support/command_line_helpers.rb +14 -9
- data/spec/support/github_helpers.rb +21 -21
- data/spec/support/rspec_stub_helpers.rb +2 -2
- metadata +18 -16
data/lib/git_reflow.rb
CHANGED
@@ -14,102 +14,91 @@ require 'git_reflow/git_server/bit_bucket'
|
|
14
14
|
require 'git_reflow/os_detector'
|
15
15
|
require 'git_reflow/sandbox'
|
16
16
|
require 'git_reflow/git_helpers'
|
17
|
+
require 'git_reflow/merge_error'
|
17
18
|
|
18
19
|
module GitReflow
|
19
20
|
include Sandbox
|
20
21
|
include GitHelpers
|
21
|
-
|
22
22
|
extend self
|
23
23
|
|
24
|
+
DEFAULT_EDITOR = "#{ENV['EDITOR']}".freeze || "vi".freeze
|
25
|
+
|
24
26
|
def status(destination_branch)
|
25
27
|
pull_request = git_server.find_open_pull_request( :from => current_branch, :to => destination_branch )
|
26
28
|
|
27
29
|
if pull_request.nil?
|
28
|
-
|
29
|
-
|
30
|
+
say "\nNo pull request exists for #{current_branch} -> #{destination_branch}", :notice
|
31
|
+
say "Run 'git reflow review #{destination_branch}' to start the review process", :notice
|
30
32
|
else
|
31
|
-
|
33
|
+
say "Here's the status of your review:"
|
32
34
|
pull_request.display_pull_request_summary
|
33
|
-
ask_to_open_in_browser(pull_request.html_url)
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
38
|
def review(options = {})
|
38
|
-
options[
|
39
|
+
options[:base] ||= 'master'
|
39
40
|
create_pull_request = true
|
40
41
|
|
41
|
-
fetch_destination options[
|
42
|
+
fetch_destination options[:base]
|
42
43
|
|
43
44
|
begin
|
44
45
|
push_current_branch
|
45
46
|
|
46
|
-
existing_pull_request = git_server.find_open_pull_request( from: current_branch, to: options[
|
47
|
+
existing_pull_request = git_server.find_open_pull_request( from: current_branch, to: options[:base] )
|
47
48
|
if existing_pull_request
|
48
49
|
say "A pull request already exists for these branches:", :notice
|
49
50
|
existing_pull_request.display_pull_request_summary
|
50
|
-
ask_to_open_in_browser(existing_pull_request.html_url)
|
51
51
|
else
|
52
|
-
unless options[
|
52
|
+
unless options[:title] || options[:body]
|
53
53
|
pull_request_msg_file = "#{GitReflow.git_root_dir}/.git/GIT_REFLOW_PR_MSG"
|
54
|
-
default_editor = "#{ENV['EDITOR']}"
|
55
|
-
|
56
|
-
if default_editor.empty?
|
57
|
-
default_editor = 'vi'
|
58
|
-
end
|
59
54
|
|
60
55
|
File.open(pull_request_msg_file, 'w') do |file|
|
61
|
-
file.write(options[
|
56
|
+
file.write(options[:title] || GitReflow.current_branch)
|
62
57
|
end
|
63
58
|
|
64
|
-
GitReflow.run("#{
|
59
|
+
GitReflow.run("#{GitReflow.git_editor_comand} #{pull_request_msg_file}", with_system: true)
|
65
60
|
|
66
61
|
pr_msg = File.read(pull_request_msg_file).split(/[\r\n]|\r\n/).map(&:strip)
|
67
62
|
title = pr_msg.shift
|
68
63
|
|
69
64
|
File.delete(pull_request_msg_file)
|
70
65
|
|
71
|
-
unless pr_msg.empty?
|
66
|
+
unless pr_msg.empty?
|
72
67
|
pr_msg.shift if pr_msg.first.empty?
|
73
68
|
end
|
74
69
|
|
75
|
-
options[
|
76
|
-
options[
|
70
|
+
options[:title] = title
|
71
|
+
options[:body] = "#{pr_msg.join("\n")}\n"
|
77
72
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
73
|
+
say "\nReview your PR:\n"
|
74
|
+
say "--------\n"
|
75
|
+
say "Title:\n#{options[:title]}\n\n"
|
76
|
+
say "Body:\n#{options[:body]}\n"
|
77
|
+
say "--------\n"
|
83
78
|
|
84
79
|
create_pull_request = ask("Submit pull request? (Y)") =~ /y/i
|
85
80
|
end
|
86
81
|
|
87
82
|
if create_pull_request
|
88
|
-
pull_request = git_server.create_pull_request(title: options[
|
89
|
-
body: options[
|
83
|
+
pull_request = git_server.create_pull_request(title: options[:title] || options[:body],
|
84
|
+
body: options[:body],
|
90
85
|
head: "#{remote_user}:#{current_branch}",
|
91
|
-
base: options[
|
86
|
+
base: options[:base])
|
92
87
|
|
93
|
-
|
94
|
-
ask_to_open_in_browser(pull_request.html_url)
|
88
|
+
say "Successfully created pull request ##{pull_request.number}: #{pull_request.title}\nPull Request URL: #{pull_request.html_url}\n", :success
|
95
89
|
else
|
96
90
|
say "Review aborted. No pull request has been created.", :review_halted
|
97
91
|
end
|
98
92
|
end
|
99
93
|
rescue Github::Error::UnprocessableEntity => e
|
100
|
-
|
94
|
+
say "Github Error: #{e.to_s}", :error
|
101
95
|
rescue StandardError => e
|
102
|
-
|
96
|
+
say "\nError: #{e.inspect}", :error
|
103
97
|
end
|
104
98
|
end
|
105
99
|
|
106
100
|
def deliver(options = {})
|
107
|
-
|
108
|
-
base_branch = options['base'] || 'master'
|
109
|
-
|
110
|
-
update_current_branch
|
111
|
-
fetch_destination(base_branch)
|
112
|
-
update_destination(feature_branch)
|
101
|
+
base_branch = options[:base] || 'master'
|
113
102
|
|
114
103
|
begin
|
115
104
|
existing_pull_request = git_server.find_open_pull_request( :from => current_branch, :to => base_branch )
|
@@ -118,42 +107,10 @@ module GitReflow
|
|
118
107
|
say "No pull request exists for #{remote_user}:#{current_branch}\nPlease submit your branch for review first with \`git reflow review\`", :deliver_halted
|
119
108
|
else
|
120
109
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
if existing_pull_request.good_to_merge?(force: options['skip_lgtm'])
|
128
|
-
puts "Merging pull request ##{existing_pull_request.number}: '#{existing_pull_request.title}', from '#{existing_pull_request.feature_branch_name}' into '#{existing_pull_request.base_branch_name}'"
|
129
|
-
|
130
|
-
update_destination(base_branch)
|
131
|
-
merge_feature_branch(feature_branch,
|
132
|
-
:destination_branch => base_branch,
|
133
|
-
:pull_request_number => existing_pull_request.number,
|
134
|
-
:lgtm_authors => existing_pull_request.approvals,
|
135
|
-
:message => commit_message)
|
136
|
-
committed = run_command_with_label 'git commit', with_system: true
|
137
|
-
|
138
|
-
if committed
|
139
|
-
say "Merge complete!", :success
|
140
|
-
|
141
|
-
# check if user always wants to push and cleanup, otherwise ask
|
142
|
-
always_deploy_and_cleanup = GitReflow::Config.get('reflow.always-deploy-and-cleanup') == "true"
|
143
|
-
deploy_and_cleanup = always_deploy_and_cleanup || (ask "Would you like to push this branch to your remote repo and cleanup your feature branch? ") =~ /^y/i
|
144
|
-
|
145
|
-
if deploy_and_cleanup
|
146
|
-
run_command_with_label "git push origin #{base_branch}"
|
147
|
-
run_command_with_label "git push origin :#{feature_branch}"
|
148
|
-
run_command_with_label "git branch -D #{feature_branch}"
|
149
|
-
puts "Nice job buddy."
|
150
|
-
else
|
151
|
-
puts "Cleanup halted. Local changes were not pushed to remote repo.".colorize(:red)
|
152
|
-
puts "To reset and go back to your branch run \`git reset --hard origin/#{base_branch} && git checkout #{feature_branch}\`"
|
153
|
-
end
|
154
|
-
else
|
155
|
-
say "There were problems commiting your feature... please check the errors above and try again.", :error
|
156
|
-
end
|
110
|
+
if existing_pull_request.good_to_merge?(force: options[:skip_lgtm])
|
111
|
+
# displays current status and prompts user for confirmation
|
112
|
+
self.status base_branch
|
113
|
+
existing_pull_request.merge!(options)
|
157
114
|
else
|
158
115
|
say existing_pull_request.rejection_message, :deliver_halted
|
159
116
|
end
|
@@ -162,7 +119,7 @@ module GitReflow
|
|
162
119
|
rescue Github::Error::UnprocessableEntity => e
|
163
120
|
errors = JSON.parse(e.response_message[:body])
|
164
121
|
error_messages = errors["errors"].collect {|error| "GitHub Error: #{error["message"].gsub(/^base\s/, '')}" unless error["message"].nil?}.compact.join("\n")
|
165
|
-
|
122
|
+
say "Github Error: #{error_messages}", :error
|
166
123
|
end
|
167
124
|
end
|
168
125
|
|