Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 883 lines (736 sloc) 23.992 kB
84a6dfc @winton Adding shitty version of -h
authored
1 require 'rubygems'
2
23755b8 @winton Forgot to require fileutils
authored
3 require 'fileutils'
8280c0f @winton Retrieving ticket titles successfully
authored
4 require 'open-uri'
5 require 'uri'
6 require 'yaml'
7
f90ae20 @winton Branch creation and pull requests working
authored
8 gem 'launchy', '= 2.0.5'
9 require 'launchy'
10
8280c0f @winton Retrieving ticket titles successfully
authored
11 gem 'yajl-ruby', '= 1.1.0'
12 require 'yajl'
13
a888bdb @winton Shouldn't add lib/gem_template to load paths, Ruby gets confused if s…
authored
14 $:.unshift File.dirname(__FILE__)
afb42f7 @winton Using new version of Bundler, fixing lib file
authored
15
8280c0f @winton Retrieving ticket titles successfully
authored
16 require "ext/string"
17
18 class Gitcycle
19
20 API =
21 if ENV['ENV'] == 'development'
22 "http://127.0.0.1:8080/api"
23 else
b36ca3d @winton Allowing user to QA from source repo, temporarily using gitcycle.blea…
authored
24 "http://gitcycle.bleacherreport.com/api"
8280c0f @winton Retrieving ticket titles successfully
authored
25 end
26
55acb57 @winton Eliminating Aruba, adding simplecov
authored
27 def initialize(args=nil)
121f6eb @winton Ready and QA cucumber features
authored
28 $remotes = {}
29
48f6795 @winton Started on cucumber specs
authored
30 if ENV['CONFIG']
31 @config_path = File.expand_path(ENV['CONFIG'])
32 else
33 @config_path = File.expand_path("~/.gitcycle.yml")
34 end
55acb57 @winton Eliminating Aruba, adding simplecov
authored
35
8280c0f @winton Retrieving ticket titles successfully
authored
36 load_config
37 load_git
55acb57 @winton Eliminating Aruba, adding simplecov
authored
38
39 start(args) if args
8280c0f @winton Retrieving ticket titles successfully
authored
40 end
41
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
42 def branch(*args)
43 url = args.detect { |arg| arg =~ /^https?:\/\// }
44 title = args.detect { |arg| arg =~ /\s/ }
45
46 exec_git(:branch, args) unless url || title
9a97b0a @winton gitc track becomes gitc checkout
authored
47
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
48 require_git && require_configs
49
f254f37 @winton Adding target branch name to beginning of ticket branch name
authored
50 params = {
51 'branch[source]' => branches(:current => true)
52 }
53
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
54 if url && url.include?('lighthouseapp.com/')
f254f37 @winton Adding target branch name to beginning of ticket branch name
authored
55 params.merge!('branch[lighthouse_url]' => url)
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
56 elsif url && url.include?('github.com/')
f254f37 @winton Adding target branch name to beginning of ticket branch name
authored
57 params.merge!('branch[issue_url]' => url)
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
58 elsif url
59 puts "Gitcycle only supports Lighthouse or Github Issue URLs.".red
60 exit
61 elsif title
f254f37 @winton Adding target branch name to beginning of ticket branch name
authored
62 params.merge!(
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
63 'branch[name]' => title,
64 'branch[title]' => title
f254f37 @winton Adding target branch name to beginning of ticket branch name
authored
65 )
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
66 else
67 exec_git(:branch, args)
68 end
69
082ec96 @winton New branch scenario, fixing ready scenario, stubbing out Launchy.open
authored
70 unless yes?("\nYour work will eventually merge into '#{params['branch[source]']}'. Is this correct?")
757ddbd @winton Getting all specs passing
authored
71 params['branch[source]'] = q("What branch would you like to eventually merge into?")
22e6b8b @winton gitc branch collaborator fixes, cucumber features for reopening pull …
authored
72 end
73
757ddbd @winton Getting all specs passing
authored
74 source = params['branch[source]']
22e6b8b @winton gitc branch collaborator fixes, cucumber features for reopening pull …
authored
75 if source.include?('/')
76 params['branch[home]'], params['branch[source]'] = source.split('/')
77 params['branch[collab]'] = 1
082ec96 @winton New branch scenario, fixing ready scenario, stubbing out Launchy.open
authored
78 end
79
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
80 puts "\nRetrieving branch information from gitcycle.\n".green
81 branch = get('branch', params)
82 name = branch['name']
83
84 begin
85 owner, repo = branch['repo'].split(':')
22e6b8b @winton gitc branch collaborator fixes, cucumber features for reopening pull …
authored
86 branch['home'] ||= @git_login
1f80a35 @winton Making collaborator branches apart of gitc branch questions, gitc rea…
authored
87
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
88 unless yes?("Would you like to name your branch '#{name}'?")
89 name = q("\nWhat would you like to name your branch?")
90 name = name.gsub(/[\s\W]/, '-')
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
91 end
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
92
93 checkout_remote_branch(
22e6b8b @winton gitc branch collaborator fixes, cucumber features for reopening pull …
authored
94 :owner => branch['collab'] ? branch['home'] : owner,
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
95 :repo => repo,
96 :branch => branch['source'],
97 :target => name
98 )
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
99 rescue SystemExit, Interrupt
100 puts "\nDeleting branch from gitcycle.\n".green
101 branch = get('branch',
102 'branch[name]' => branch['name'],
103 'create' => 0,
104 'reset' => 1
105 )
106 end
107
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
108 puts "Sending branch information to gitcycle.".green
109 get('branch',
110 'branch[home]' => branch['home'],
111 'branch[name]' => branch['name'],
112 'branch[rename]' => name != branch['name'] ? name : nil,
113 'branch[source]' => branch['source']
114 )
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
115
116 puts "\n"
117 end
118
119 def checkout(*args)
0d39d9a @winton Collaborator checkout and push scenarios
authored
120 if args.length != 1 || options?(args)
1045cc6 @winton Preserving as much original functionality of commit/push/pull as poss…
authored
121 exec_git(:checkout, args)
122 end
123
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
124 require_git && require_config
125
0d39d9a @winton Collaborator checkout and push scenarios
authored
126 if args[0] =~ /^https?:\/\//
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
127 puts "\nRetrieving branch information from gitcycle.\n".green
6efa304 @winton README, make sure checkout doesn't create branch on accident
authored
128 branch = get('branch', 'branch[lighthouse_url]' => args[0], 'create' => 0)
129 if branch
130 checkout_or_track(:name => branch['name'], :remote => 'origin')
131 else
132 puts "\nBranch not found!\n".red
557471d Adding helpful reminder to suggest a gitc branch if the branch can no…
Alex Rockwell authored
133 puts "\nDid you mean: gitc branch #{args[0]}\n".yellow
6efa304 @winton README, make sure checkout doesn't create branch on accident
authored
134 end
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
135 else
0d39d9a @winton Collaborator checkout and push scenarios
authored
136 remote, branch = args[0].split('/')
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
137 remote, branch = nil, remote if branch.nil?
01c2eae @winton Create/update collab branch every time collab syntax is used
authored
138 collab = branch && remote
9a97b0a @winton gitc track becomes gitc checkout
authored
139
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
140 unless branches(:match => branch)
aadc111 @winton Specs passing, trying repo owner as backup on collaborator checkouts …
authored
141 og_remote = nil
a9e51c3 @winton Collaboration via git checkout <user> <branch>
authored
142
aadc111 @winton Specs passing, trying repo owner as backup on collaborator checkouts …
authored
143 puts "\nRetrieving repo information from gitcycle.\n".green
144 repo = get('repo')
145 remote = repo['owner'] unless collab
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
146
aadc111 @winton Specs passing, trying repo owner as backup on collaborator checkouts …
authored
147 output = add_remote_and_fetch(
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
148 :owner => remote,
149 :repo => @git_repo
a9e51c3 @winton Collaboration via git checkout <user> <branch>
authored
150 )
aadc111 @winton Specs passing, trying repo owner as backup on collaborator checkouts …
authored
151
152 if output.include?('ERROR')
153 og_remote = remote
154 remote = repo["owner"]
155
156 add_remote_and_fetch(
157 :owner => remote,
158 :repo => @git_repo
159 )
160 end
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
161
162 puts "Creating branch '#{branch}' from '#{remote}/#{branch}'.\n".green
aadc111 @winton Specs passing, trying repo owner as backup on collaborator checkouts …
authored
163 output = run("git branch --no-track #{branch} #{remote}/#{branch}")
164
165 if output.include?("fatal")
166 puts "Could not find branch #{"'#{og_remote}/#{branch}' or " if og_remote}'#{remote}/#{branch}'.\n".red
167 exit
168 end
01c2eae @winton Create/update collab branch every time collab syntax is used
authored
169 end
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
170
01c2eae @winton Create/update collab branch every time collab syntax is used
authored
171 if collab
172 puts "Sending branch information to gitcycle.".green
173 get('branch',
174 'branch[home]' => remote,
175 'branch[name]' => branch,
176 'branch[source]' => branch,
177 'branch[collab]' => 1,
178 'create' => 1
179 )
a9e51c3 @winton Collaboration via git checkout <user> <branch>
authored
180 end
9a97b0a @winton gitc track becomes gitc checkout
authored
181
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
182 puts "Checking out '#{branch}'.\n".green
b1f0a26 @winton Silencing git output where possible
authored
183 run("git checkout -q #{branch}")
29de883 @winton Associate multiple branches with same Lighthouse ticket, no need for …
authored
184 end
9a97b0a @winton gitc track becomes gitc checkout
authored
185 end
186 alias :co :checkout
187
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
188 def commit(*args)
189 msg = nil
2d086ee @winton gitc commit --no-add option, doing a straight commit if merge commit
authored
190 no_add = args.delete("--no-add")
a4ed4b7 Added commit_all
Michael Schaefermeyer authored
191
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
192 if args.empty?
1045cc6 @winton Preserving as much original functionality of commit/push/pull as poss…
authored
193 require_git && require_config
194
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
195 puts "\nRetrieving branch information from gitcycle.\n".green
196 branch = get('branch',
197 'branch[name]' => branches(:current => true),
198 'create' => 0
199 )
200
201 id = branch["lighthouse_url"].match(/tickets\/(\d+)/)[1] rescue nil
202
203 if branch && id
2752fd9 Fixing commit
Michael Schaefermeyer authored
204 msg = "[##{id}]"
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
205 msg += " #{branch["title"]}" if branch["title"]
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
206 end
a4ed4b7 Added commit_all
Michael Schaefermeyer authored
207 end
208
2d086ee @winton gitc commit --no-add option, doing a straight commit if merge commit
authored
209 if no_add
210 cmd = "git commit"
211 else
212 cmd = "git add . && git add . -u && git commit -a"
213 end
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
214
2d086ee @winton gitc commit --no-add option, doing a straight commit if merge commit
authored
215 if File.exists?("#{Dir.pwd}/.git/MERGE_HEAD")
216 Kernel.exec(cmd)
217 elsif msg
218 run(cmd + " -m #{msg.dump}")
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
219 Kernel.exec("git commit --amend")
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
220 elsif args.empty?
2d086ee @winton gitc commit --no-add option, doing a straight commit if merge commit
authored
221 Kernel.exec(cmd)
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
222 else
223 exec_git(:commit, args)
224 end
a4ed4b7 Added commit_all
Michael Schaefermeyer authored
225 end
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
226 alias :ci :commit
a4ed4b7 Added commit_all
Michael Schaefermeyer authored
227
158a0ec @winton Everything working but qa command (but almost there)
authored
228 def discuss(*issues)
8fddd92 @winton Support for labeling, improvements on everything else
authored
229 require_git && require_config
230
158a0ec @winton Everything working but qa command (but almost there)
authored
231 if issues.empty?
b893709 @winton gitc ready will now create a pull request if it does not exist
authored
232 branch = create_pull_request
158a0ec @winton Everything working but qa command (but almost there)
authored
233
234 if branch == false
235 puts "Branch not found.\n".red
236 elsif branch['issue_url']
a1af87c @winton Labeling issues with Discuss
authored
237 puts "\nLabeling issue as 'Discuss'.\n".green
238 get('label',
239 'branch[name]' => branch['name'],
240 'labels' => [ 'Discuss' ]
241 )
242
aca2a9b @winton More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…
authored
243 puts "Opening issue: #{branch['issue_url']}\n".green
158a0ec @winton Everything working but qa command (but almost there)
authored
244 Launchy.open(branch['issue_url'])
245 else
246 puts "You must push code before opening a pull request.\n".red
247 end
248 else
b893709 @winton gitc ready will now create a pull request if it does not exist
authored
249 puts "\nRetrieving branch information from gitcycle.\n".green
250
158a0ec @winton Everything working but qa command (but almost there)
authored
251 get('branch', 'issues' => issues, 'scope' => 'repo').each do |branch|
252 if branch['issue_url']
aca2a9b @winton More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…
authored
253 puts "Opening issue: #{branch['issue_url']}\n".green
158a0ec @winton Everything working but qa command (but almost there)
authored
254 Launchy.open(branch['issue_url'])
255 end
256 end
8fddd92 @winton Support for labeling, improvements on everything else
authored
257 end
158a0ec @winton Everything working but qa command (but almost there)
authored
258 end
8fddd92 @winton Support for labeling, improvements on everything else
authored
259
1045cc6 @winton Preserving as much original functionality of commit/push/pull as poss…
authored
260 def pull(*args)
261 exec_git(:pull, args) if args.length > 0
262
8fddd92 @winton Support for labeling, improvements on everything else
authored
263 require_git && require_config
264
d0f9f25 @winton gitc pull now works with non-feature branches
authored
265 current_branch = branches(:current => true)
266
8fddd92 @winton Support for labeling, improvements on everything else
authored
267 puts "\nRetrieving branch information from gitcycle.\n".green
268 branch = get('branch',
d0f9f25 @winton gitc pull now works with non-feature branches
authored
269 'branch[name]' => current_branch,
158a0ec @winton Everything working but qa command (but almost there)
authored
270 'include' => [ 'repo' ],
8fddd92 @winton Support for labeling, improvements on everything else
authored
271 'create' => 0
272 )
273
757ddbd @winton Getting all specs passing
authored
274 if branch && branch['collab']
0763f83 @winton Fixing gitc pull for non-ticket and non-collab branches, more work on…
authored
275 # Merge from collab
276 merge_remote_branch(
277 :owner => branch['home'],
278 :repo => branch['repo']['name'],
0d39d9a @winton Collaborator checkout and push scenarios
authored
279 :branch => branch['source']
0763f83 @winton Fixing gitc pull for non-ticket and non-collab branches, more work on…
authored
280 )
b004bc4 @winton undefined method `[]' for false:FalseClass on gitc pull
authored
281 elsif branch
3cc398a @winton Fixing gitc pull
authored
282 # Merge from upstream source branch
0763f83 @winton Fixing gitc pull for non-ticket and non-collab branches, more work on…
authored
283 merge_remote_branch(
284 :owner => branch['repo']['owner'],
285 :repo => branch['repo']['name'],
286 :branch => branch['source']
287 )
3cc398a @winton Fixing gitc pull
authored
288 else
289 puts "\nRetrieving repo information from gitcycle.\n".green
290 repo = get('repo')
291
292 # Merge from upstream branch with same name
293 merge_remote_branch(
294 :owner => repo['owner'],
295 :repo => repo['name'],
296 :branch => current_branch
297 )
0763f83 @winton Fixing gitc pull for non-ticket and non-collab branches, more work on…
authored
298 end
d0f9f25 @winton gitc pull now works with non-feature branches
authored
299
757ddbd @winton Getting all specs passing
authored
300 unless branch && branch['collab']
0763f83 @winton Fixing gitc pull for non-ticket and non-collab branches, more work on…
authored
301 # Merge from origin
302 merge_remote_branch(
303 :owner => @git_login,
304 :repo => @git_repo,
305 :branch => current_branch
306 )
348722c @winton Tracking "home" user for feature branches, adding REPO=owner cucumber…
authored
307 end
a9e51c3 @winton Collaboration via git checkout <user> <branch>
authored
308
309 branch
8fddd92 @winton Support for labeling, improvements on everything else
authored
310 end
311
1045cc6 @winton Preserving as much original functionality of commit/push/pull as poss…
authored
312 def push(*args)
313 exec_git(:push, args) if args.length > 0
314
315 require_git && require_config
316
0d39d9a @winton Collaborator checkout and push scenarios
authored
317 branch = pull
1f80a35 @winton Making collaborator branches apart of gitc branch questions, gitc rea…
authored
318
0d39d9a @winton Collaborator checkout and push scenarios
authored
319 if branch['collab']
320 puts "\nPushing branch '#{branch['home']}/#{branch['name']}'.\n".green
321 run("git push #{branch['home']} #{branch['name']} -q")
322 else
b08700b @winton Fix for gitc push
authored
323 puts "\nPushing branch 'origin/#{branch['name']}'.\n".green
2f30552 @winton Another gitc push fix
authored
324 run("git push origin #{branch['name']} -q")
0d39d9a @winton Collaborator checkout and push scenarios
authored
325 end
36826bd @winton gitc is now a drop-in replacement for git
authored
326 end
327
158a0ec @winton Everything working but qa command (but almost there)
authored
328 def qa(*issues)
8fddd92 @winton Support for labeling, improvements on everything else
authored
329 require_git && require_config
330
8ddfccd @winton QA command mostly finished
authored
331 if issues.empty?
332 puts "\n"
333 get('qa_branch').each do |branches|
deda521 @tongueroo Update qa branch naming convention to qa_rc_[username]
tongueroo authored
334 puts "qa_#{branches['source']}_#{branches['user']}".green
8ddfccd @winton QA command mostly finished
authored
335 branches['branches'].each do |branch|
336 puts " #{"issue ##{branch['issue']}".yellow}\t#{branch['user']}/#{branch['branch']}"
337 end
338 puts "\n"
339 end
ab8180f @winton Work on resolving qa branches
authored
340 elsif issues.first == 'fail' || issues.first == 'pass'
341 branch = branches(:current => true)
25271cd @winton gitc qa pass issue.id is now an immediate QA merge command
authored
342 pass_fail = issues.first
343 label = pass_fail.capitalize
344 issues = issues[1..-1]
345
346 if pass_fail == 'pass' && !issues.empty?
347 puts "\nWARNING: #{
348 issues.length == 1 ? "This issue" : "These issues"
349 } will merge straight into '#{branch}' without testing.\n".red
350
351 if yes?("Continue?")
352 qa_branch = create_qa_branch(
353 :instructions => false,
354 :issues => issues,
355 :source => branch
356 )
357 `git checkout qa_#{qa_branch['source']}_#{qa_branch['user']} -q`
358 $remotes = {}
359 qa('pass')
360 else
361 exit
362 end
363 elsif branch =~ /^qa_/
ab8180f @winton Work on resolving qa branches
authored
364 puts "\nRetrieving branch information from gitcycle.\n".green
365 qa_branch = get('qa_branch', :source => branch.gsub(/^qa_/, ''))
366
63cd36b @winton Conflict detection on all merges
authored
367 if pass_fail == 'pass'
8e1e57e @winton Silence git fetch, track branch on gitc qa pass
authored
368 checkout_or_track(:name => qa_branch['source'], :remote => 'origin')
63cd36b @winton Conflict detection on all merges
authored
369 end
aca2a9b @winton More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…
authored
370
63cd36b @winton Conflict detection on all merges
authored
371 if issues.empty?
d9aaae0 @winton First pass at README, adding ability to specify tickets to fail or pa…
authored
372 branches = qa_branch['branches']
373 else
374 branches = qa_branch['branches'].select do |b|
375 issues.include?(b['issue'])
376 end
63cd36b @winton Conflict detection on all merges
authored
377 end
d9aaae0 @winton First pass at README, adding ability to specify tickets to fail or pa…
authored
378
25271cd @winton gitc qa pass issue.id is now an immediate QA merge command
authored
379 if pass_fail == 'pass' && issues.empty?
380 owner, repo = qa_branch['repo'].split(':')
381 merge_remote_branch(
382 :owner => owner,
383 :repo => repo,
384 :branch => "qa_#{qa_branch['source']}_#{qa_branch['user']}",
385 :type => :from_qa
386 )
412a22d @winton QA pass now merges entire QA branch
authored
387 end
d9aaae0 @winton First pass at README, adding ability to specify tickets to fail or pa…
authored
388
412a22d @winton QA pass now merges entire QA branch
authored
389 unless issues.empty?
390 branches.each do |branch|
d9aaae0 @winton First pass at README, adding ability to specify tickets to fail or pa…
authored
391 puts "\nLabeling issue #{branch['issue']} as '#{label}'.\n".green
392 get('label',
63cd36b @winton Conflict detection on all merges
authored
393 'qa_branch[source]' => qa_branch['source'],
d9aaae0 @winton First pass at README, adding ability to specify tickets to fail or pa…
authored
394 'issue' => branch['issue'],
395 'labels' => [ label ]
396 )
397 end
398 end
8ddfccd @winton QA command mostly finished
authored
399
32a3342 @winton Fixing bug where issues not marked Fail
authored
400 if issues.empty?
63cd36b @winton Conflict detection on all merges
authored
401 puts "\nLabeling all issues as '#{label}'.\n".green
402 get('label',
403 'qa_branch[source]' => qa_branch['source'],
404 'labels' => [ label ]
405 )
406 end
ab8180f @winton Work on resolving qa branches
authored
407 else
408 puts "\nYou are not in a QA branch.\n".red
409 end
8ddfccd @winton QA command mostly finished
authored
410 elsif issues.first == 'resolved'
411 branch = branches(:current => true)
412
413 if branch =~ /^qa_/
414 puts "\nRetrieving branch information from gitcycle.\n".green
415 qa_branch = get('qa_branch', :source => branch.gsub(/^qa_/, ''))
63cd36b @winton Conflict detection on all merges
authored
416
417 branches = qa_branch['branches']
418 conflict = branches.detect { |branch| branch['conflict'] }
8ddfccd @winton QA command mostly finished
authored
419
63cd36b @winton Conflict detection on all merges
authored
420 if qa_branch && conflict
421 puts "Committing merge resolution of #{conflict['branch']} (issue ##{conflict['issue']}).\n".green
422 run("git add . && git add . -u && git commit -a -F .git/MERGE_MSG")
8ddfccd @winton QA command mostly finished
authored
423
63cd36b @winton Conflict detection on all merges
authored
424 puts "Pushing merge resolution of #{conflict['branch']} (issue ##{conflict['issue']}).\n".green
b1f0a26 @winton Silencing git output where possible
authored
425 run("git push origin qa_#{qa_branch['source']}_#{qa_branch['user']} -q")
8ddfccd @winton QA command mostly finished
authored
426
63cd36b @winton Conflict detection on all merges
authored
427 puts "\nDe-conflicting on gitcycle.\n".green
428 get('qa_branch',
429 'issues' => branches.collect { |branch| branch['issue'] }
430 )
8ddfccd @winton QA command mostly finished
authored
431
63cd36b @winton Conflict detection on all merges
authored
432 create_qa_branch(
433 :preserve => true,
434 :range => (branches.index(conflict)+1..-1),
435 :qa_branch => qa_branch
436 )
8ddfccd @winton QA command mostly finished
authored
437 else
438 puts "Couldn't find record of a conflicted merge.\n".red
439 end
440 else
441 puts "\nYou aren't on a QA branch.\n".red
442 end
443 else
444 create_qa_branch(:issues => issues)
158a0ec @winton Everything working but qa command (but almost there)
authored
445 end
8fddd92 @winton Support for labeling, improvements on everything else
authored
446 end
447
158a0ec @winton Everything working but qa command (but almost there)
authored
448 def ready(*issues)
8fddd92 @winton Support for labeling, improvements on everything else
authored
449 require_git && require_config
450
1f80a35 @winton Making collaborator branches apart of gitc branch questions, gitc rea…
authored
451 branch = pull
4bbca75 @winton Cucumber scenarios for collaborating, still need to update ticket inf…
authored
452
22e6b8b @winton gitc branch collaborator fixes, cucumber features for reopening pull …
authored
453 if branch && !branch['collab']
e9f3801 @winton gitc ready will reopen pull requests
authored
454 force = branch['labels'] && branch['labels'].include?('Pass')
455 branch = create_pull_request(branch, force)
4bbca75 @winton Cucumber scenarios for collaborating, still need to update ticket inf…
authored
456 end
1f80a35 @winton Making collaborator branches apart of gitc branch questions, gitc rea…
authored
457
458 if branch == false
459 puts "Branch not found.\n".red
22e6b8b @winton gitc branch collaborator fixes, cucumber features for reopening pull …
authored
460 elsif branch['collab']
4bbca75 @winton Cucumber scenarios for collaborating, still need to update ticket inf…
authored
461 remote, branch = branch['home'], branch['source']
1f80a35 @winton Making collaborator branches apart of gitc branch questions, gitc rea…
authored
462 puts "\nPushing branch '#{remote}/#{branch}'.\n".green
b1f0a26 @winton Silencing git output where possible
authored
463 run("git push #{remote} #{branch} -q")
1f80a35 @winton Making collaborator branches apart of gitc branch questions, gitc rea…
authored
464 elsif branch['issue_url']
465 puts "\nLabeling issue as 'Pending Review'.\n".green
158a0ec @winton Everything working but qa command (but almost there)
authored
466 get('label',
1f80a35 @winton Making collaborator branches apart of gitc branch questions, gitc rea…
authored
467 'branch[name]' => branch['name'],
468 'labels' => [ 'Pending Review' ]
158a0ec @winton Everything working but qa command (but almost there)
authored
469 )
1f80a35 @winton Making collaborator branches apart of gitc branch questions, gitc rea…
authored
470
471 puts "Opening issue: #{branch['issue_url']}\n".green
472 Launchy.open(branch['issue_url'])
473 else
474 puts "You have not pushed any commits to '#{branch['name']}'.\n".red
158a0ec @winton Everything working but qa command (but almost there)
authored
475 end
476 end
477
b544c3b @winton gitc reviewed => gitc review pass, gitc reviewed fail => gitc review …
authored
478 def review(pass_fail, *issues)
158a0ec @winton Everything working but qa command (but almost there)
authored
479 require_git && require_config
480
b544c3b @winton gitc reviewed => gitc review pass, gitc reviewed fail => gitc review …
authored
481 if pass_fail == 'fail'
ff86f35 @tongueroo gitc reviewed pass|fail
tongueroo authored
482 label = 'Fail'
483 else
484 label = 'Pending QA'
485 end
486
158a0ec @winton Everything working but qa command (but almost there)
authored
487 if issues.empty?
ff86f35 @tongueroo gitc reviewed pass|fail
tongueroo authored
488 puts "\nLabeling issue as '#{label}'.\n".green
158a0ec @winton Everything working but qa command (but almost there)
authored
489 get('label',
490 'branch[name]' => branches(:current => true),
ff86f35 @tongueroo gitc reviewed pass|fail
tongueroo authored
491 'labels' => [ label ]
158a0ec @winton Everything working but qa command (but almost there)
authored
492 )
493 else
ff86f35 @tongueroo gitc reviewed pass|fail
tongueroo authored
494 puts "\nLabeling issues as '#{label}'.\n".green
158a0ec @winton Everything working but qa command (but almost there)
authored
495 get('label',
496 'issues' => issues,
ff86f35 @tongueroo gitc reviewed pass|fail
tongueroo authored
497 'labels' => [ label ],
158a0ec @winton Everything working but qa command (but almost there)
authored
498 'scope' => 'repo'
499 )
500 end
8fddd92 @winton Support for labeling, improvements on everything else
authored
501 end
502
8280c0f @winton Retrieving ticket titles successfully
authored
503 def setup(login, repo, token)
b36ca3d @winton Allowing user to QA from source repo, temporarily using gitcycle.blea…
authored
504 repo = "#{login}/#{repo}" unless repo.include?('/')
505 @config[repo] = [ login, token ]
8280c0f @winton Retrieving ticket titles successfully
authored
506 save_config
48f6795 @winton Started on cucumber specs
authored
507 puts "\nConfiguration saved.\n".green
8280c0f @winton Retrieving ticket titles successfully
authored
508 end
509
55acb57 @winton Eliminating Aruba, adding simplecov
authored
510 def start(args=[])
511 command = args.shift
36826bd @winton gitc is now a drop-in replacement for git
authored
512
513 `git --help`.scan(/\s{3}(\w+)\s{3}/).flatten.each do |cmd|
514 if command == cmd && !self.respond_to?(command)
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
515 exec_git(cmd, args)
36826bd @winton gitc is now a drop-in replacement for git
authored
516 end
517 end
518
55acb57 @winton Eliminating Aruba, adding simplecov
authored
519 if command.nil?
520 puts "\nNo command specified\n".red
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
521 elsif command =~ /^-/
84a6dfc @winton Adding shitty version of -h
authored
522 command_not_recognized
55acb57 @winton Eliminating Aruba, adding simplecov
authored
523 elsif self.respond_to?(command)
524 send(command, *args)
525 else
84a6dfc @winton Adding shitty version of -h
authored
526 command_not_recognized
55acb57 @winton Eliminating Aruba, adding simplecov
authored
527 end
528 end
529
8280c0f @winton Retrieving ticket titles successfully
authored
530 private
531
315a5b7 @winton Added confirmation for branch to base feature branch off of
authored
532 def add_remote_and_fetch(options={})
533 owner = options[:owner]
534 repo = options[:repo]
535
536 unless $remotes[owner]
537 $remotes[owner] = true
0763f83 @winton Fixing gitc pull for non-ticket and non-collab branches, more work on…
authored
538
0e64f93 @winton No longer removing and re-adding remotes that already exist
authored
539 unless remotes(:match => owner)
540 puts "Adding remote repo '#{owner}/#{repo}'.\n".green
541 run("git remote add #{owner} git@github.com:#{owner}/#{repo}.git")
542 end
9a97b0a @winton gitc track becomes gitc checkout
authored
543
0763f83 @winton Fixing gitc pull for non-ticket and non-collab branches, more work on…
authored
544 puts "Fetching remote '#{owner}'.\n".green
545 run("git fetch -q #{owner}")
546 end
315a5b7 @winton Added confirmation for branch to base feature branch off of
authored
547 end
548
474d481 @winton Successful pull request
authored
549 def branches(options={})
3e17abf @winton Fixing fatal git error resulting from pulling non-existent branch, re…
authored
550 b = `git branch#{" -a" if options[:all]}#{" -r" if options[:remote]}`
474d481 @winton Successful pull request
authored
551 if options[:current]
552 b.match(/\*\s+(.+)/)[1]
553 elsif options[:match]
40103ca @winton Fixing branch match regex and version bump (0.1.7)
authored
554 b.match(/([\s]+|origin\/)(#{options[:match]})$/)[2] rescue nil
474d481 @winton Successful pull request
authored
555 else
556 b
557 end
558 end
559
8e1e57e @winton Silence git fetch, track branch on gitc qa pass
authored
560 def checkout_or_track(options={})
561 name = options[:name]
562 remote = options[:remote]
563
564 if branches(:match => name)
565 puts "Checking out branch '#{name}'.\n".green
b1f0a26 @winton Silencing git output where possible
authored
566 run("git checkout #{name} -q")
8e1e57e @winton Silence git fetch, track branch on gitc qa pass
authored
567 else
568 puts "Tracking branch '#{remote}/#{name}'.\n".green
569 run("git fetch -q #{remote}")
b1f0a26 @winton Silencing git output where possible
authored
570 run("git checkout -q -b #{name} #{remote}/#{name}")
8e1e57e @winton Silence git fetch, track branch on gitc qa pass
authored
571 end
572
b1f0a26 @winton Silencing git output where possible
authored
573 run("git pull #{remote} #{name} -q")
8e1e57e @winton Silence git fetch, track branch on gitc qa pass
authored
574 end
575
71543d8 @winton Version bump (0.1.6)
authored
576 def checkout_remote_branch(options={})
577 owner = options[:owner]
578 repo = options[:repo]
579 branch = options[:branch]
af48d2c @winton Need to make sure when a branch is created, it is always from the pri…
authored
580 target = options[:target] || branch
581
582 if branches(:match => target)
98e41a9 @winton Fixing error on checkout_remote_branch when user chooses not to overw…
authored
583 if yes?("You already have a branch called '#{target}'. Overwrite?")
9c07a39 @winton If Github is down, `gitc qa` can accidentally merge into master. This…
authored
584 run_safe("git push origin :#{target} -q")
585 run_safe("git checkout master -q")
586 run_safe("git branch -D #{target}")
98e41a9 @winton Fixing error on checkout_remote_branch when user chooses not to overw…
authored
587 else
9c07a39 @winton If Github is down, `gitc qa` can accidentally merge into master. This…
authored
588 run_safe("git checkout #{target} -q")
589 run_safe("git pull origin #{target} -q")
af48d2c @winton Need to make sure when a branch is created, it is always from the pri…
authored
590 return
591 end
592 end
71543d8 @winton Version bump (0.1.6)
authored
593
315a5b7 @winton Added confirmation for branch to base feature branch off of
authored
594 add_remote_and_fetch(options)
595
af48d2c @winton Need to make sure when a branch is created, it is always from the pri…
authored
596 puts "Checking out remote branch '#{target}' from '#{owner}/#{repo}/#{branch}'.\n".green
b1f0a26 @winton Silencing git output where possible
authored
597 run("git checkout -q -b #{target} #{owner}/#{branch}")
71543d8 @winton Version bump (0.1.6)
authored
598
3e17abf @winton Fixing fatal git error resulting from pulling non-existent branch, re…
authored
599 puts "Fetching remote 'origin'.\n".green
600 run("git fetch -q origin")
601
602 if branches(:remote => true, :match => "origin/#{target}")
603 puts "Pulling 'origin/#{target}'.\n".green
b1f0a26 @winton Silencing git output where possible
authored
604 run("git pull origin #{target} -q")
3e17abf @winton Fixing fatal git error resulting from pulling non-existent branch, re…
authored
605 end
7fba45d @tongueroo Pull origin branch whenever checking out remote branch
tongueroo authored
606
607 puts "Pushing 'origin/#{target}'.\n".green
82c2e15 @winton Making sure we don't update undefined values, removing unnecessary Gi…
authored
608 run("git push origin #{target} -q")
71543d8 @winton Version bump (0.1.6)
authored
609 end
610
84a6dfc @winton Adding shitty version of -h
authored
611 def command_not_recognized
612 readme = "https://github.com/winton/gitcycle/blob/master/README.md"
613 puts "\nCommand not recognized.".red
614 puts "\nOpening #{readme}\n".green
615 Launchy.open(readme)
616 end
617
e9f3801 @winton gitc ready will reopen pull requests
authored
618 def create_pull_request(branch=nil, force=false)
0763f83 @winton Fixing gitc pull for non-ticket and non-collab branches, more work on…
authored
619 unless branch
620 puts "\nRetrieving branch information from gitcycle.\n".green
621 branch = get('branch',
622 'branch[name]' => branches(:current => true),
623 'create' => 0
624 )
625 end
b893709 @winton gitc ready will now create a pull request if it does not exist
authored
626
e9f3801 @winton gitc ready will reopen pull requests
authored
627 if branch && (force || !branch['issue_url'])
b893709 @winton gitc ready will now create a pull request if it does not exist
authored
628 puts "Creating GitHub pull request.\n".green
629 branch = get('branch',
630 'branch[create_pull_request]' => true,
631 'branch[name]' => branch['name'],
632 'create' => 0
633 )
634 end
635
636 branch
637 end
638
8ddfccd @winton QA command mostly finished
authored
639 def create_qa_branch(options)
25271cd @winton gitc qa pass issue.id is now an immediate QA merge command
authored
640 instructions = options[:instructions]
8ddfccd @winton QA command mostly finished
authored
641 issues = options[:issues]
642 range = options[:range] || (0..-1)
25271cd @winton gitc qa pass issue.id is now an immediate QA merge command
authored
643 source = options[:source]
8ddfccd @winton QA command mostly finished
authored
644
645 if (issues && !issues.empty?) || options[:qa_branch]
646 if options[:qa_branch]
647 qa_branch = options[:qa_branch]
648 else
25271cd @winton gitc qa pass issue.id is now an immediate QA merge command
authored
649 unless source
650 source = branches(:current => true)
651
652 unless yes?("\nDo you want to create a QA branch from '#{source}'?")
653 source = q("What branch would you like to base this QA branch off of?")
654 end
c3cb3e6 @winton No longer restricting cross-branch QAing (be careful)
authored
655 end
656
8ddfccd @winton QA command mostly finished
authored
657 puts "\nRetrieving branch information from gitcycle.\n".green
c3cb3e6 @winton No longer restricting cross-branch QAing (be careful)
authored
658 qa_branch = get('qa_branch', 'issues' => issues, 'source' => source)
8ddfccd @winton QA command mostly finished
authored
659 end
660
661 source = qa_branch['source']
deda521 @tongueroo Update qa branch naming convention to qa_rc_[username]
tongueroo authored
662 name = "qa_#{source}_#{qa_branch['user']}"
8ddfccd @winton QA command mostly finished
authored
663
664 unless qa_branch['branches'].empty?
07b5ffd @winton Removing ability to QA pull requests based on a different branch than…
authored
665 qa_branch['branches'][range].each do |branch|
666 if source != branch['source']
667 puts "You can only QA issues based on '#{source}'\n".red
668 exit
669 end
670 end
671
8ddfccd @winton QA command mostly finished
authored
672 unless options[:preserve]
55acb57 @winton Eliminating Aruba, adding simplecov
authored
673 if branches(:match => name, :all => true)
8ddfccd @winton QA command mostly finished
authored
674 puts "Deleting old QA branch '#{name}'.\n".green
0e1561c @winton Checkout master before doing a branch -D
authored
675 if branches(:match => name)
b1f0a26 @winton Silencing git output where possible
authored
676 run("git checkout master -q")
0e1561c @winton Checkout master before doing a branch -D
authored
677 run("git branch -D #{name}")
678 end
b1f0a26 @winton Silencing git output where possible
authored
679 run("git push origin :#{name} -q")
8ddfccd @winton QA command mostly finished
authored
680 end
681
af48d2c @winton Need to make sure when a branch is created, it is always from the pri…
authored
682 checkout_remote_branch(
683 :owner => @git_login,
684 :repo => @git_repo,
685 :branch => source,
686 :target => name
687 )
688
8ddfccd @winton QA command mostly finished
authored
689 puts "\n"
690 end
691
692 qa_branch['branches'][range].each do |branch|
693 issue = branch['issue']
694 owner, repo = branch['repo'].split(':')
348722c @winton Tracking "home" user for feature branches, adding REPO=owner cucumber…
authored
695 home = branch['home']
2d9afb2 @winton Warning if merging different source branches into QA branch
authored
696
aca2a9b @winton More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…
authored
697 output = merge_remote_branch(
348722c @winton Tracking "home" user for feature branches, adding REPO=owner cucumber…
authored
698 :owner => home,
aca2a9b @winton More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…
authored
699 :repo => repo,
2d9afb2 @winton Warning if merging different source branches into QA branch
authored
700 :branch => branch['branch'],
63cd36b @winton Conflict detection on all merges
authored
701 :issue => issue,
702 :issues => qa_branch['branches'].collect { |b| b['issue'] },
703 :type => :to_qa
aca2a9b @winton More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…
authored
704 )
8ddfccd @winton QA command mostly finished
authored
705 end
ab8180f @winton Work on resolving qa branches
authored
706
25271cd @winton gitc qa pass issue.id is now an immediate QA merge command
authored
707 unless options[:instructions] == false
708 puts "\nType '".yellow + "gitc qa pass".green + "' to approve all issues in this branch.\n".yellow
709 puts "Type '".yellow + "gitc qa fail".red + "' to reject all issues in this branch.\n".yellow
710 end
8ddfccd @winton QA command mostly finished
authored
711 end
25271cd @winton gitc qa pass issue.id is now an immediate QA merge command
authored
712
713 qa_branch
8ddfccd @winton QA command mostly finished
authored
714 end
715 end
716
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
717 def exec_git(command, args)
718 args.unshift("git", command)
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
719 Kernel.exec(*args.collect(&:to_s))
4e67d77 @winton Moving commit_all -> commit, fixing up a bit
authored
720 end
721
63cd36b @winton Conflict detection on all merges
authored
722 def fix_conflict(options)
723 owner = options[:owner]
724 repo = options[:repo]
725 branch = options[:branch]
726 issue = options[:issue]
727 issues = options[:issues]
728 type = options[:type]
729
730 if $? != 0
731 puts "Conflict occurred when merging '#{branch}'#{" (issue ##{issue})" if issue}.\n".red
732
412a22d @winton QA pass now merges entire QA branch
authored
733 if type == :to_qa
63cd36b @winton Conflict detection on all merges
authored
734 puts "Please resolve this conflict with '#{owner}'.\n".yellow
735
736 puts "\nSending conflict information to gitcycle.\n".green
737 get('qa_branch', 'issues' => issues, "conflict_#{type}" => issue)
738
739 puts "Type 'gitc qa resolved' when finished resolving.\n".yellow
740 exit
741 end
742 elsif type # from_qa or to_qa
743 branch = branches(:current => true)
744 puts "Pushing branch '#{branch}'.\n".green
b1f0a26 @winton Silencing git output where possible
authored
745 run("git push origin #{branch} -q")
63cd36b @winton Conflict detection on all merges
authored
746 end
747 end
748
8ddfccd @winton QA command mostly finished
authored
749 def get(path, hash={})
f90ae20 @winton Branch creation and pull requests working
authored
750 hash.merge!(
b36ca3d @winton Allowing user to QA from source repo, temporarily using gitcycle.blea…
authored
751 :login => @login,
752 :token => @token
f90ae20 @winton Branch creation and pull requests working
authored
753 )
754
8280c0f @winton Retrieving ticket titles successfully
authored
755 params = ''
474d481 @winton Successful pull request
authored
756 hash[:session] = 0
8280c0f @winton Retrieving ticket titles successfully
authored
757 hash.each do |k, v|
cb7de2b @winton Removing aruba dependency, fixing array-as-parameter issue in Ruby 1.8.x
authored
758 if v && v.is_a?(::Array)
759 params << "#{URI.escape(k.to_s)}=#{URI.escape(v.inspect)}&"
760 elsif v
f90ae20 @winton Branch creation and pull requests working
authored
761 params << "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}&"
762 end
8280c0f @winton Retrieving ticket titles successfully
authored
763 end
764 params.chop! # trailing &
765
7ac9603 @winton Features fixed, way better error handling for API requests
authored
766 begin
767 json = open("#{API}/#{path}.json?#{params}").read
768 rescue Exception
769 puts "\nCould not connect to Gitcycle.".red
770 puts "\nPlease verify your Internet connection and try again later.\n".yellow
771 exit
772 end
773
a4ed4b7 Added commit_all
Michael Schaefermeyer authored
774 match = json.match(/Gitcycle error reference code (\d+)/)
775 error = match && match[1]
7ac9603 @winton Features fixed, way better error handling for API requests
authored
776
777 if error
778 puts "\nSomething went wrong :(".red
779 puts "\nEmail error code #{error} to wwelsh@bleacherreport.com.".yellow
780 puts "\nInclude a gist of your terminal output if possible.\n".yellow
781 exit
782 else
783 Yajl::Parser.parse(json)
784 end
8280c0f @winton Retrieving ticket titles successfully
authored
785 end
786
787 def load_config
788 if File.exists?(@config_path)
789 @config = YAML.load(File.read(@config_path))
790 else
791 @config = {}
792 end
793 end
794
795 def load_git
796 path = "#{Dir.pwd}/.git/config"
797 if File.exists?(path)
8fddd92 @winton Support for labeling, improvements on everything else
authored
798 @git_url = File.read(path).match(/\[remote "origin"\][^\[]*url = ([^\n]+)/m)[1]
8280c0f @winton Retrieving ticket titles successfully
authored
799 @git_repo = @git_url.match(/\/(.+)\./)[1]
800 @git_login = @git_url.match(/:(.+)\//)[1]
b36ca3d @winton Allowing user to QA from source repo, temporarily using gitcycle.blea…
authored
801 @login, @token = @config["#{@git_login}/#{@git_repo}"] rescue [ nil, nil ]
8280c0f @winton Retrieving ticket titles successfully
authored
802 end
803 end
aca2a9b @winton More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…
authored
804
805 def merge_remote_branch(options={})
806 owner = options[:owner]
807 repo = options[:repo]
808 branch = options[:branch]
809
315a5b7 @winton Added confirmation for branch to base feature branch off of
authored
810 add_remote_and_fetch(options)
aca2a9b @winton More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…
authored
811
3cc398a @winton Fixing gitc pull
authored
812 if branches(:remote => true, :match => "#{owner}/#{branch}")
813 puts "\nMerging remote branch '#{branch}' from '#{owner}/#{repo}'.\n".green
757ddbd @winton Getting all specs passing
authored
814 run("git merge #{owner}/#{branch}")
63cd36b @winton Conflict detection on all merges
authored
815
3cc398a @winton Fixing gitc pull
authored
816 fix_conflict(options)
817 end
aca2a9b @winton More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…
authored
818 end
8280c0f @winton Retrieving ticket titles successfully
authored
819
1045cc6 @winton Preserving as much original functionality of commit/push/pull as poss…
authored
820 def options?(args)
03a4ea9 @winton gitc <ticket url> becomes gitc branch <ticket url>, clarifying philos…
authored
821 args.any? { |arg| arg =~ /^-/ }
1045cc6 @winton Preserving as much original functionality of commit/push/pull as poss…
authored
822 end
823
8ddfccd @winton QA command mostly finished
authored
824 def remotes(options={})
825 b = `git remote`
826 if options[:match]
827 b.match(/^(#{options[:match]})$/)[1] rescue nil
828 else
829 b
830 end
831 end
832
8280c0f @winton Retrieving ticket titles successfully
authored
833 def require_config
b36ca3d @winton Allowing user to QA from source repo, temporarily using gitcycle.blea…
authored
834 unless @login && @token
f90ae20 @winton Branch creation and pull requests working
authored
835 puts "\nGitcycle configuration not found.".red
836 puts "Are you in the right repository?".yellow
837 puts "Have you set up this repository at http://gitcycle.com?\n".yellow
48f6795 @winton Started on cucumber specs
authored
838 exit
8280c0f @winton Retrieving ticket titles successfully
authored
839 end
840 end
841
842 def require_git
843 unless @git_url && @git_repo && @git_login
f90ae20 @winton Branch creation and pull requests working
authored
844 puts "\norigin entry within '.git/config' not found!".red
845 puts "Are you sure you are in a git repository?\n".yellow
48f6795 @winton Started on cucumber specs
authored
846 exit
8280c0f @winton Retrieving ticket titles successfully
authored
847 end
848 end
849
850 def save_config
436cbce @tongueroo Make sure config dir exist before writing files to it
tongueroo authored
851 FileUtils.mkdir_p(File.dirname(@config_path))
8280c0f @winton Retrieving ticket titles successfully
authored
852 File.open(@config_path, 'w') do |f|
853 f.write(YAML.dump(@config))
854 end
855 end
474d481 @winton Successful pull request
authored
856
f90ae20 @winton Branch creation and pull requests working
authored
857 def q(question, extra='')
858 puts "#{question.yellow}#{extra}"
55acb57 @winton Eliminating Aruba, adding simplecov
authored
859 $input ? $input.shift : $stdin.gets.strip
474d481 @winton Successful pull request
authored
860 end
861
862 def run(cmd)
863 if ENV['RUN'] == '0'
864 puts cmd
865 else
aadc111 @winton Specs passing, trying repo owner as backup on collaborator checkouts …
authored
866 `#{cmd} 2>&1`
474d481 @winton Successful pull request
authored
867 end
868 end
869
9c07a39 @winton If Github is down, `gitc qa` can accidentally merge into master. This…
authored
870 def run_safe(cmd)
871 run(cmd)
872 if $? != 0
873 puts "The last command was supposed to run without error, but it didn't :(\n".red
3ee3a8c @winton Version bump (0.2.17)
authored
874 puts "Please copy this session's output and send it to gitcycle@bleacherreport.com.\n".yellow
b205614 @winton Forgot the exit
authored
875 exit
9c07a39 @winton If Github is down, `gitc qa` can accidentally merge into master. This…
authored
876 end
877 end
878
474d481 @winton Successful pull request
authored
879 def yes?(question)
f90ae20 @winton Branch creation and pull requests working
authored
880 q(question, " (#{"y".green}/#{"n".red})").downcase[0..0] == 'y'
474d481 @winton Successful pull request
authored
881 end
2fc3222 On failing to retrieve branch information from gitcycle, gives a sugg…
Alex Rockwell authored
882 end
Something went wrong with that request. Please try again.