git_reflow 0.8.9 → 0.8.10
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 +5 -5
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +41 -44
- data/README.md +461 -0
- data/_config.yml +1 -0
- data/circle.yml +5 -5
- data/exe/git-reflow +36 -36
- data/git_reflow.gemspec +6 -11
- data/lib/git_reflow.rb +0 -1
- data/lib/git_reflow/git_server.rb +63 -63
- data/lib/git_reflow/git_server/bit_bucket.rb +101 -101
- data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +84 -84
- data/lib/git_reflow/git_server/git_hub.rb +1 -1
- data/lib/git_reflow/git_server/git_hub/pull_request.rb +1 -1
- data/lib/git_reflow/rspec.rb +2 -2
- data/lib/git_reflow/version.rb +1 -1
- data/lib/git_reflow/workflows/core.rb +235 -238
- data/lib/git_reflow/workflows/flat_merge.rb +10 -10
- data/spec/fixtures/awesome_workflow.rb +7 -7
- data/spec/fixtures/workflow_with_super.rb +8 -8
- data/spec/lib/git_reflow/git_server/bit_bucket_spec.rb +81 -81
- data/spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb +4 -4
- data/spec/lib/git_reflow/git_server_spec.rb +101 -101
- data/spec/lib/git_reflow/sandbox_spec.rb +1 -1
- data/spec/lib/git_reflow/workflow_spec.rb +59 -59
- data/spec/lib/git_reflow/workflows/core_spec.rb +3 -4
- data/spec/lib/git_reflow/workflows/flat_merge_spec.rb +60 -59
- data/spec/support/fixtures.rb +54 -54
- data/spec/support/github_helpers.rb +99 -109
- metadata +17 -39
- data/README.rdoc +0 -461
- data/lib/git_reflow/os_detector.rb +0 -23
@@ -1,84 +1,84 @@
|
|
1
|
-
require 'git_reflow/git_server/pull_request'
|
2
|
-
|
3
|
-
module GitReflow
|
4
|
-
module GitServer
|
5
|
-
class BitBucket
|
6
|
-
class PullRequest < GitReflow::GitServer::PullRequest
|
7
|
-
def initialize(attributes)
|
8
|
-
self.number = attributes.id
|
9
|
-
self.description = attributes.body || attributes.description
|
10
|
-
self.html_url = "#{attributes.source.repository.links.html.href}/pull-request/#{self.number}"
|
11
|
-
self.feature_branch_name = attributes.source.branch.name[/[^:]+$/]
|
12
|
-
self.base_branch_name = attributes.destination.branch.name[/[^:]+$/]
|
13
|
-
self.build = Build.new
|
14
|
-
self.source_object = attributes
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.create(options = {})
|
18
|
-
self.new GitReflow.git_server.connection.repos.pull_requests.create(
|
19
|
-
GitReflow.git_server.class.remote_user,
|
20
|
-
GitReflow.git_server.class.remote_repo_name,
|
21
|
-
title: options[:title],
|
22
|
-
description: options[:body] || options[:description],
|
23
|
-
source: {
|
24
|
-
branch: { name: GitReflow.git_server.class.current_branch },
|
25
|
-
repository: { full_name: "#{GitReflow.git_server.class.remote_user}/#{GitReflow.git_server.class.remote_repo_name}" }
|
26
|
-
},
|
27
|
-
destination: {
|
28
|
-
branch: { name: options[:base] }
|
29
|
-
},
|
30
|
-
reviewers: [username: GitReflow.git_server.class.user])
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.find_open(to: 'master', from: GitReflow.git_server.class.current_branch)
|
34
|
-
begin
|
35
|
-
matching_pull = GitReflow.git_server.connection.repos.pull_requests.all(GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, limit: 1).select do |pr|
|
36
|
-
pr.source.branch.name == from and
|
37
|
-
pr.destination.branch.name == to
|
38
|
-
end.first
|
39
|
-
|
40
|
-
if matching_pull
|
41
|
-
self.new matching_pull
|
42
|
-
end
|
43
|
-
rescue ::BitBucket::Error::NotFound => e
|
44
|
-
GitReflow.git_server.say "No BitBucket repo found for #{GitReflow.git_server.class.remote_user}/#{GitReflow.git_server.class.remote_repo_name}", :error
|
45
|
-
rescue ::BitBucket::Error::Forbidden => e
|
46
|
-
GitReflow.git_server.say "You don't have API access to this repo", :error
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def commit_author
|
51
|
-
# use the author of the pull request
|
52
|
-
self.author.username
|
53
|
-
end
|
54
|
-
|
55
|
-
def comments
|
56
|
-
GitReflow.git_server.connection.repos.pull_requests.comments.all(GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, self.id)
|
57
|
-
end
|
58
|
-
|
59
|
-
def last_comment
|
60
|
-
last_comment = comments.first
|
61
|
-
return "" unless last_comment
|
62
|
-
"#{last_comment.content.raw}"
|
63
|
-
end
|
64
|
-
|
65
|
-
def reviewers
|
66
|
-
return [] unless comments.size > 0
|
67
|
-
comments.map {|c| c.user.username }.uniq - [GitReflow.git_server.class.user]
|
68
|
-
end
|
69
|
-
|
70
|
-
def approvals
|
71
|
-
approved = []
|
72
|
-
|
73
|
-
GitReflow.git_server.connection.repos.pull_requests.activity(GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, self.id).each do |activity|
|
74
|
-
break unless activity.respond_to?(:approval) and activity.approval.user.username != GitReflow.git_server.class.user
|
75
|
-
approved |= [activity.approval.user.username]
|
76
|
-
end
|
77
|
-
|
78
|
-
approved
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
1
|
+
require 'git_reflow/git_server/pull_request'
|
2
|
+
|
3
|
+
module GitReflow
|
4
|
+
module GitServer
|
5
|
+
class BitBucket
|
6
|
+
class PullRequest < GitReflow::GitServer::PullRequest
|
7
|
+
def initialize(attributes)
|
8
|
+
self.number = attributes.id
|
9
|
+
self.description = attributes.body || attributes.description
|
10
|
+
self.html_url = "#{attributes.source.repository.links.html.href}/pull-request/#{self.number}"
|
11
|
+
self.feature_branch_name = attributes.source.branch.name[/[^:]+$/]
|
12
|
+
self.base_branch_name = attributes.destination.branch.name[/[^:]+$/]
|
13
|
+
self.build = Build.new
|
14
|
+
self.source_object = attributes
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create(options = {})
|
18
|
+
self.new GitReflow.git_server.connection.repos.pull_requests.create(
|
19
|
+
GitReflow.git_server.class.remote_user,
|
20
|
+
GitReflow.git_server.class.remote_repo_name,
|
21
|
+
title: options[:title],
|
22
|
+
description: options[:body] || options[:description],
|
23
|
+
source: {
|
24
|
+
branch: { name: GitReflow.git_server.class.current_branch },
|
25
|
+
repository: { full_name: "#{GitReflow.git_server.class.remote_user}/#{GitReflow.git_server.class.remote_repo_name}" }
|
26
|
+
},
|
27
|
+
destination: {
|
28
|
+
branch: { name: options[:base] }
|
29
|
+
},
|
30
|
+
reviewers: [username: GitReflow.git_server.class.user])
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.find_open(to: 'master', from: GitReflow.git_server.class.current_branch)
|
34
|
+
begin
|
35
|
+
matching_pull = GitReflow.git_server.connection.repos.pull_requests.all(GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, limit: 1).select do |pr|
|
36
|
+
pr.source.branch.name == from and
|
37
|
+
pr.destination.branch.name == to
|
38
|
+
end.first
|
39
|
+
|
40
|
+
if matching_pull
|
41
|
+
self.new matching_pull
|
42
|
+
end
|
43
|
+
rescue ::BitBucket::Error::NotFound => e
|
44
|
+
GitReflow.git_server.say "No BitBucket repo found for #{GitReflow.git_server.class.remote_user}/#{GitReflow.git_server.class.remote_repo_name}", :error
|
45
|
+
rescue ::BitBucket::Error::Forbidden => e
|
46
|
+
GitReflow.git_server.say "You don't have API access to this repo", :error
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def commit_author
|
51
|
+
# use the author of the pull request
|
52
|
+
self.author.username
|
53
|
+
end
|
54
|
+
|
55
|
+
def comments
|
56
|
+
GitReflow.git_server.connection.repos.pull_requests.comments.all(GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, self.id)
|
57
|
+
end
|
58
|
+
|
59
|
+
def last_comment
|
60
|
+
last_comment = comments.first
|
61
|
+
return "" unless last_comment
|
62
|
+
"#{last_comment.content.raw}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def reviewers
|
66
|
+
return [] unless comments.size > 0
|
67
|
+
comments.map {|c| c.user.username }.uniq - [GitReflow.git_server.class.user]
|
68
|
+
end
|
69
|
+
|
70
|
+
def approvals
|
71
|
+
approved = []
|
72
|
+
|
73
|
+
GitReflow.git_server.connection.repos.pull_requests.activity(GitReflow.git_server.class.remote_user, GitReflow.git_server.class.remote_repo_name, self.id).each do |activity|
|
74
|
+
break unless activity.respond_to?(:approval) and activity.approval.user.username != GitReflow.git_server.class.user
|
75
|
+
approved |= [activity.approval.user.username]
|
76
|
+
end
|
77
|
+
|
78
|
+
approved
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/git_reflow/rspec.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require_relative 'rspec/command_line_helpers'
|
2
|
-
require_relative 'rspec/stub_helpers'
|
1
|
+
require_relative 'rspec/command_line_helpers'
|
2
|
+
require_relative 'rspec/stub_helpers'
|
data/lib/git_reflow/version.rb
CHANGED
@@ -1,238 +1,235 @@
|
|
1
|
-
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../..')
|
2
|
-
require 'git_reflow/workflow'
|
3
|
-
|
4
|
-
module GitReflow
|
5
|
-
module Workflows
|
6
|
-
# This class contains the core workflow for git-reflow. Going forward, this
|
7
|
-
# will act as the base class for customizing and extending git-reflow.
|
8
|
-
class Core
|
9
|
-
include GitReflow::Workflow
|
10
|
-
|
11
|
-
# Sets up the required git configurations that git-reflow depends on.
|
12
|
-
#
|
13
|
-
# @param local [Boolean] whether to configure git-reflow specific to the current project
|
14
|
-
# @param enterprise [Boolean] whether to configure git-reflow for use with Github Enterprise
|
15
|
-
command(:setup, defaults: {local: false, enterprise: false}) do |**params|
|
16
|
-
reflow_options = { project_only: params[:local], enterprise: params[:enterprise] }
|
17
|
-
existing_git_include_paths = GitReflow::Config.get('include.path', all: true).split("\n")
|
18
|
-
|
19
|
-
unless File.exist?(GitReflow::Config::CONFIG_FILE_PATH) or existing_git_include_paths.include?(GitReflow::Config::CONFIG_FILE_PATH)
|
20
|
-
GitReflow.say "We'll walk you through setting up git-reflow's defaults for all your projects.", :notice
|
21
|
-
GitReflow.say "In the future, you can run \`git-reflow setup\` from the root of any project you want to setup differently.", :notice
|
22
|
-
GitReflow.
|
23
|
-
GitReflow.
|
24
|
-
GitReflow.
|
25
|
-
GitReflow
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
menu.
|
31
|
-
|
32
|
-
|
33
|
-
menu.choice('
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
GitReflow::Config.set "constants.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
GitReflow
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
#
|
47
|
-
#
|
48
|
-
# @
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
GitReflow.run_command_with_label "git
|
58
|
-
GitReflow.run_command_with_label "git
|
59
|
-
GitReflow.run_command_with_label "git
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
#
|
66
|
-
# @option
|
67
|
-
# @option
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
existing_pull_request
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
params[:
|
101
|
-
|
102
|
-
|
103
|
-
say "
|
104
|
-
say "
|
105
|
-
say "
|
106
|
-
say "
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
#
|
131
|
-
#
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
say "
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
staging_branch_name =
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
GitReflow.run_command_with_label "git
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
#
|
194
|
-
#
|
195
|
-
# @option
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
# $ git
|
227
|
-
# $ git
|
228
|
-
#
|
229
|
-
#
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
1
|
+
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../..')
|
2
|
+
require 'git_reflow/workflow'
|
3
|
+
|
4
|
+
module GitReflow
|
5
|
+
module Workflows
|
6
|
+
# This class contains the core workflow for git-reflow. Going forward, this
|
7
|
+
# will act as the base class for customizing and extending git-reflow.
|
8
|
+
class Core
|
9
|
+
include GitReflow::Workflow
|
10
|
+
|
11
|
+
# Sets up the required git configurations that git-reflow depends on.
|
12
|
+
#
|
13
|
+
# @param local [Boolean] whether to configure git-reflow specific to the current project
|
14
|
+
# @param enterprise [Boolean] whether to configure git-reflow for use with Github Enterprise
|
15
|
+
command(:setup, defaults: {local: false, enterprise: false}) do |**params|
|
16
|
+
reflow_options = { project_only: params[:local], enterprise: params[:enterprise] }
|
17
|
+
existing_git_include_paths = GitReflow::Config.get('include.path', all: true).split("\n")
|
18
|
+
|
19
|
+
unless File.exist?(GitReflow::Config::CONFIG_FILE_PATH) or existing_git_include_paths.include?(GitReflow::Config::CONFIG_FILE_PATH)
|
20
|
+
GitReflow.say "We'll walk you through setting up git-reflow's defaults for all your projects.", :notice
|
21
|
+
GitReflow.say "In the future, you can run \`git-reflow setup --local\` from the root of any project you want to setup differently.", :notice
|
22
|
+
GitReflow.run "touch #{GitReflow::Config::CONFIG_FILE_PATH}"
|
23
|
+
GitReflow.say "Created #{GitReflow::Config::CONFIG_FILE_PATH} for git-reflow specific configurations.", :notice
|
24
|
+
GitReflow::Config.add "include.path", GitReflow::Config::CONFIG_FILE_PATH, global: true
|
25
|
+
GitReflow.say "Added #{GitReflow::Config::CONFIG_FILE_PATH} to include.path in $HOME/.gitconfig.", :notice
|
26
|
+
end
|
27
|
+
|
28
|
+
choose do |menu|
|
29
|
+
menu.header = "Available remote Git Server services"
|
30
|
+
menu.prompt = "Which service would you like to use for this project? "
|
31
|
+
|
32
|
+
menu.choice('GitHub') { GitReflow::GitServer.connect reflow_options.merge({ provider: 'GitHub', silent: false }) }
|
33
|
+
menu.choice('BitBucket (team-owned repos only)') { GitReflow::GitServer.connect reflow_options.merge({ provider: 'BitBucket', silent: false }) }
|
34
|
+
end
|
35
|
+
|
36
|
+
GitReflow::Config.set "constants.minimumApprovals", ask("Set the minimum number of approvals (leaving blank will require approval from all commenters): "), local: reflow_options[:project_only]
|
37
|
+
GitReflow::Config.set "constants.approvalRegex", GitReflow::GitServer::PullRequest::DEFAULT_APPROVAL_REGEX, local: reflow_options[:project_only]
|
38
|
+
|
39
|
+
if GitReflow::Config.get('core.editor').length <= 0
|
40
|
+
GitReflow::Config.set('core.editor', GitReflow.default_editor, local: reflow_options[:project_only])
|
41
|
+
GitReflow.say "Updated git's editor (via git config key 'core.editor') to: #{GitReflow.default_editor}.", :notice
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Start a new feature branch
|
46
|
+
#
|
47
|
+
# @param feature_branch [String] the name of the branch to create your feature on
|
48
|
+
# @option base [String] the name of the base branch you want to checkout your feature from
|
49
|
+
command(:start, defaults: {base: 'master'}) do |**params|
|
50
|
+
base_branch = params[:base]
|
51
|
+
feature_branch = params[:feature_branch]
|
52
|
+
|
53
|
+
if feature_branch.nil? or feature_branch.length <= 0
|
54
|
+
GitReflow.say "usage: git-reflow start [new-branch-name]", :error
|
55
|
+
else
|
56
|
+
GitReflow.run_command_with_label "git checkout #{base_branch}"
|
57
|
+
GitReflow.run_command_with_label "git pull origin #{base_branch}"
|
58
|
+
GitReflow.run_command_with_label "git push origin #{base_branch}:refs/heads/#{feature_branch}"
|
59
|
+
GitReflow.run_command_with_label "git checkout --track -b #{feature_branch} origin/#{feature_branch}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Submit a feature branch for review
|
64
|
+
#
|
65
|
+
# @option base [String] the name of the base branch you want to merge your feature into
|
66
|
+
# @option title [String] the title of your pull request
|
67
|
+
# @option body [String] the body of your pull request
|
68
|
+
command(:review, defaults: {base: 'master'}) do |**params|
|
69
|
+
base_branch = params[:base]
|
70
|
+
create_pull_request = true
|
71
|
+
|
72
|
+
GitReflow.fetch_destination base_branch
|
73
|
+
begin
|
74
|
+
GitReflow.push_current_branch
|
75
|
+
|
76
|
+
existing_pull_request = GitReflow.git_server.find_open_pull_request( from: GitReflow.current_branch, to: base_branch )
|
77
|
+
if existing_pull_request
|
78
|
+
say "A pull request already exists for these branches:", :notice
|
79
|
+
existing_pull_request.display_pull_request_summary
|
80
|
+
else
|
81
|
+
unless params[:title] || params[:body]
|
82
|
+
pull_request_msg_file = "#{GitReflow.git_root_dir}/.git/GIT_REFLOW_PR_MSG"
|
83
|
+
|
84
|
+
File.open(pull_request_msg_file, 'w') do |file|
|
85
|
+
file.write(params[:title] || GitReflow.pull_request_template || GitReflow.current_branch)
|
86
|
+
end
|
87
|
+
|
88
|
+
GitReflow.run("#{GitReflow.git_editor_command} #{pull_request_msg_file}", with_system: true)
|
89
|
+
|
90
|
+
pr_msg = File.read(pull_request_msg_file).split(/[\r\n]|\r\n/).map(&:strip)
|
91
|
+
title = pr_msg.shift
|
92
|
+
|
93
|
+
File.delete(pull_request_msg_file)
|
94
|
+
|
95
|
+
unless pr_msg.empty?
|
96
|
+
pr_msg.shift if pr_msg.first.empty?
|
97
|
+
end
|
98
|
+
|
99
|
+
params[:title] = title
|
100
|
+
params[:body] = "#{pr_msg.join("\n")}\n"
|
101
|
+
|
102
|
+
say "\nReview your PR:\n"
|
103
|
+
say "--------\n"
|
104
|
+
say "Title:\n#{params[:title]}\n\n"
|
105
|
+
say "Body:\n#{params[:body]}\n"
|
106
|
+
say "--------\n"
|
107
|
+
|
108
|
+
create_pull_request = ask("Submit pull request? (Y)") =~ /y/i
|
109
|
+
end
|
110
|
+
|
111
|
+
if create_pull_request
|
112
|
+
pull_request = GitReflow.git_server.create_pull_request(title: params[:title] || params[:body],
|
113
|
+
body: params[:body],
|
114
|
+
head: "#{GitReflow.remote_user}:#{GitReflow.current_branch}",
|
115
|
+
base: params[:base])
|
116
|
+
|
117
|
+
say "Successfully created pull request ##{pull_request.number}: #{pull_request.title}\nPull Request URL: #{pull_request.html_url}\n", :success
|
118
|
+
else
|
119
|
+
say "Review aborted. No pull request has been created.", :review_halted
|
120
|
+
end
|
121
|
+
end
|
122
|
+
rescue Github::Error::UnprocessableEntity => e
|
123
|
+
say "Github Error: #{e.to_s}", :error
|
124
|
+
rescue StandardError => e
|
125
|
+
say "\nError: #{e.inspect}", :error
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# Checks the status of an existing pull request
|
130
|
+
#
|
131
|
+
# @option destination_branch [String] the branch you're merging your feature into ('master' is default)
|
132
|
+
command(:status, defaults: {destination_branch: 'master'}) do |**params|
|
133
|
+
pull_request = GitReflow.git_server.find_open_pull_request( :from => GitReflow.current_branch, :to => params[:destination_branch] )
|
134
|
+
|
135
|
+
if pull_request.nil?
|
136
|
+
say "No pull request exists for #{GitReflow.current_branch} -> #{params[:destination_branch]}", :notice
|
137
|
+
say "Run 'git reflow review #{params[:destination_branch]}' to start the review process", :notice
|
138
|
+
else
|
139
|
+
say "Here's the status of your review:"
|
140
|
+
pull_request.display_pull_request_summary
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
command(:deploy) do |**params|
|
145
|
+
destination_server = params[:destination_server] || 'default'
|
146
|
+
deploy_command = GitReflow::Config.get("reflow.deploy-to-#{destination_server}-command", local: true)
|
147
|
+
|
148
|
+
# first check is to allow for automated setup
|
149
|
+
if deploy_command.empty?
|
150
|
+
deploy_command = ask("Enter the command you use to deploy to #{destination_server} (leaving blank will skip deployment)")
|
151
|
+
end
|
152
|
+
|
153
|
+
# second check is to see if the user wants to skip
|
154
|
+
if deploy_command.empty?
|
155
|
+
say "Skipping deployment..."
|
156
|
+
false
|
157
|
+
else
|
158
|
+
GitReflow::Config.set("reflow.deploy-to-#{destination_server}-command", deploy_command, local: true)
|
159
|
+
run_command_with_label(deploy_command, with_system: true)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# Merge and deploy a feature branch to a staging branch
|
164
|
+
command(:stage) do |**params|
|
165
|
+
feature_branch_name = GitReflow.current_branch
|
166
|
+
staging_branch_name = GitReflow::Config.get('reflow.staging-branch', local: true)
|
167
|
+
|
168
|
+
if staging_branch_name.empty?
|
169
|
+
staging_branch_name = GitReflow.ask("What's the name of your staging branch? (default: 'staging') ")
|
170
|
+
staging_branch_name = 'staging' if staging_branch_name.strip == ''
|
171
|
+
GitReflow::Config.set('reflow.staging-branch', staging_branch_name, local: true)
|
172
|
+
end
|
173
|
+
|
174
|
+
GitReflow.run_command_with_label "git checkout #{staging_branch_name}"
|
175
|
+
GitReflow.run_command_with_label "git pull origin #{staging_branch_name}"
|
176
|
+
|
177
|
+
if GitReflow.run_command_with_label "git merge #{feature_branch_name}", with_system: true
|
178
|
+
GitReflow.run_command_with_label "git push origin #{staging_branch_name}"
|
179
|
+
|
180
|
+
staged = self.deploy(destination_server: :staging)
|
181
|
+
|
182
|
+
if staged
|
183
|
+
GitReflow.say "Deployed to Staging.", :success
|
184
|
+
else
|
185
|
+
GitReflow.say "There were issues deploying to staging.", :error
|
186
|
+
end
|
187
|
+
else
|
188
|
+
GitReflow.say "There were issues merging your feature branch to staging.", :error
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# Deliver a feature branch to a base branch
|
193
|
+
#
|
194
|
+
# @option base [String] base branch to merge your feature branch into
|
195
|
+
# @option force [Boolean] whether to force-deliver the feature branch, ignoring any QA checks
|
196
|
+
command(:deliver, defaults: {base: 'master'}) do |**params|
|
197
|
+
begin
|
198
|
+
existing_pull_request = GitReflow.git_server.find_open_pull_request( from: GitReflow.current_branch, to: params[:base] )
|
199
|
+
|
200
|
+
if existing_pull_request.nil?
|
201
|
+
say "No pull request exists for #{GitReflow.remote_user}:#{GitReflow.current_branch}\nPlease submit your branch for review first with \`git reflow review\`", :deliver_halted
|
202
|
+
else
|
203
|
+
|
204
|
+
if existing_pull_request.good_to_merge?(force: params[:force])
|
205
|
+
# displays current status and prompts user for confirmation
|
206
|
+
self.status destination_branch: params[:base]
|
207
|
+
existing_pull_request.merge!(params)
|
208
|
+
else
|
209
|
+
say existing_pull_request.rejection_message, :deliver_halted
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
rescue Github::Error::UnprocessableEntity => e
|
215
|
+
say "Github Error: #{e.inspect}", :error
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
# Updates and synchronizes your base branch and feature branch.
|
221
|
+
#
|
222
|
+
# Performs the following:
|
223
|
+
# $ git checkout <base_branch>
|
224
|
+
# $ git pull <remote_location> <base_branch>
|
225
|
+
# $ git checkout <current_branch>
|
226
|
+
# $ git pull origin <current_branch>
|
227
|
+
# $ git merge <base_branch>
|
228
|
+
# @param remote [String] the name of the remote repository to fetch updates from (origin by default)
|
229
|
+
# @param base [String] the branch that you want to fetch updates from (master by default)
|
230
|
+
command(:refresh, defaults: {remote: 'origin', base: 'master'}) do |**params|
|
231
|
+
GitReflow.update_feature_branch(params)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|