fanforce-cli 1.1.0

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.
@@ -0,0 +1,41 @@
1
+ class Fanforce::CLI::Apps
2
+ require 'singleton'
3
+ require 'forwardable'
4
+ include Singleton
5
+
6
+ def dir_names
7
+ @dirs ||= Dir.chdir($HomeDir) do Dir['*/'].inject([]) do |dirs, d|
8
+ d = d.gsub('/', '')
9
+ next dirs if d !~ /^(app-[a-z0-9-]+)\/?$/
10
+ next dirs << d if $Filter.blank?
11
+ next dirs << d if $Filter[:dir_name].present? and $Filter[:dir_name] == d
12
+ next dirs
13
+ end end
14
+ end
15
+
16
+ def dirs
17
+ dir_names.inject([]) do |result, d|
18
+ result << "#{$HomeDir}/#{d}"
19
+ end
20
+ end
21
+
22
+ def each(&block)
23
+ cur_count = 0
24
+ total = dir_names.size
25
+ dir_names.each do |d|
26
+ cur_count += 1
27
+ app = Fanforce::CLI::App.load("#{$HomeDir}/#{d}")
28
+ Dir.chdir(app.dir) { block.call(app, cur_count, total) }
29
+ end
30
+ end
31
+
32
+ def count
33
+ dir_names.size
34
+ end
35
+
36
+ class << self
37
+ extend Forwardable
38
+ def_delegators :instance, *Fanforce::CLI::Apps.instance_methods(false)
39
+ end
40
+
41
+ end
@@ -0,0 +1,506 @@
1
+ class Fanforce::CLI
2
+ require 'fanforce/cli/commands_support'
3
+
4
+ def list_apps
5
+ puts "\n---------------------------------------------------------------------------------------------------------------\n"
6
+ puts "#{Apps.count} APPS".format(:bold,:green) + ' IN CURRENT DIRECTORY'
7
+ puts "---------------------------------------------------------------------------------------------------------------\n"
8
+ Apps.each do |app, cur_count, total|
9
+ printf "- %s\n", app.dir_name.format(:green)
10
+ end
11
+
12
+ puts "---------------------------------------------------------------------------------------------------------------\n\n" if Apps.count > 0
13
+ end
14
+
15
+ def create_app(app_id)
16
+ dir_name = "app-#{app_id}"
17
+ dir = "#{$HomeDir}/#{dir_name}"
18
+
19
+ if File.exists?("#{dir}/config.ru")
20
+ puts '---------------------------------------------------------------------------------------------------------------'
21
+ puts 'ERROR... '.format(:red,:bold) + "#{dir_name} already exists. You should run: ".format(:red) + "fanforce update #{dir_name}".format(:green)
22
+ puts '---------------------------------------------------------------------------------------------------------------'
23
+ return
24
+ end
25
+
26
+ puts "\n---------------------------------------------------------------------------------------------------------------"
27
+ puts 'CREATING FILES...'
28
+ Dir.mkdir(dir) if !File.directory?(dir)
29
+ Dir.chdir(dir)
30
+ puts "#{'Created'.format(:bold, :green)} #{dir_name}/"
31
+ app = App.load(dir)
32
+ setup_files(app)
33
+
34
+ puts "\n---------------------------------------------------------------------------------------------------------------"
35
+ puts 'RUNNING BUNDLER...'
36
+ Run.bundle_install(app.dir)
37
+
38
+ puts "\n---------------------------------------------------------------------------------------------------------------"
39
+ puts 'CREATING POW DOMAINS...'
40
+ setup_pow(app)
41
+
42
+ puts "\n---------------------------------------------------------------------------------------------------------------"
43
+ puts 'CREATING LOCAL GIT REPOSITORY...'
44
+ Run.git_init and puts '- git init'
45
+ Run.git_add and puts '- git add .'
46
+ Run.git_first_commit and puts '- git commit -m "initial fanforce commit"'
47
+
48
+ #puts "\n---------------------------------------------------------------------------------------------------------------"
49
+ #puts 'CREATING BITBUCKET REPOSITORY...'
50
+ #setup_bitbucket app
51
+ #
52
+ #puts "\n---------------------------------------------------------------------------------------------------------------"
53
+ #puts 'CREATING HEROKU APPS...'
54
+ #setup_heroku app, :staging
55
+ #setup_heroku app, :production
56
+
57
+ puts "\n---------------------------------------------------------------------------------------------------------------"
58
+ puts 'CREATING ENV VARIABLES...'
59
+ setup_envs(app, :development)
60
+
61
+ puts "\n---------------------------------------------------------------------------------------------------------------"
62
+ puts 'DONE!'.format(:bold,:green)
63
+ puts "---------------------------------------------------------------------------------------------------------------\n"
64
+ end
65
+
66
+ def update_app(app_id)
67
+ app_dir_name = "app-#{app_id}"
68
+ app_dir = "#{$HomeDir}/#{app_dir_name}"
69
+
70
+ if !File.exists?("#{app_dir}/config.ru")
71
+ puts '---------------------------------------------------------------------------------------------------------------'
72
+ puts 'ERROR... '.format(:red,:bold) + "#{app_dir_name} does not exist. You should run: ".format(:red) + "fanforce create #{app_dir_name}".format(:green)
73
+ puts '---------------------------------------------------------------------------------------------------------------'
74
+ return
75
+ end
76
+
77
+ run_update(app_dir, 1, 1)
78
+
79
+ puts "\n---------------------------------------------------------------------------------------------------------------"
80
+ puts 'DONE!'.format(:bold,:green)
81
+ puts "---------------------------------------------------------------------------------------------------------------\n"
82
+ end
83
+
84
+ ######################################################################################################################
85
+
86
+ def delete_app(app_id)
87
+ app_dir_name = "app-#{app_id}"
88
+ app_dir = "#{$HomeDir}/#{app_dir_name}"
89
+
90
+ if !File.directory?("#{app_dir}")
91
+ puts '---------------------------------------------------------------------------------------------------------------'
92
+ puts 'OOPS... '.format(:red,:bold) + "#{app_dir_name} does not exist and therefore cannot be deleted!"
93
+ puts '---------------------------------------------------------------------------------------------------------------'
94
+ return
95
+ end
96
+
97
+ app = App.load(app_dir)
98
+
99
+ puts "\n---------------------------------------------------------------------------------------------------------------"
100
+ puts 'DELETING HEROKU APPS...'
101
+ [:staging,:production].each do |environment|
102
+ next if $Config[:heroku].blank? or $Config[:heroku][environment].blank?
103
+ heroku = auth_heroku(environment)
104
+ heroku_app_name = get_heroku_app_name(app, environment)
105
+ begin
106
+ heroku.delete_app(heroku_app_name)
107
+ puts "#{'Removed '.format(:green,:bold)}" + " #{heroku_app_name}"
108
+ rescue Exception => e
109
+ puts "#{'Already Removed'.format(:green,:bold)}" + " #{heroku_app_name}"
110
+ end
111
+ end
112
+
113
+ puts "\n---------------------------------------------------------------------------------------------------------------"
114
+ puts 'DELETING BITBUCKET REPOSITORY...'
115
+ if $Config[:bitbucket].present?
116
+ bitbucket = BitBucket.new(login: $Config[:bitbucket][:user], password: $Config[:bitbucket][:password])
117
+ begin
118
+ repo = bitbucket.repos.find($Config[:bitbucket][:user], app.dir_name)
119
+ RestClient.delete("https://#{$Config[:bitbucket][:user]}:#{$Config[:bitbucket][:password]}@api.bitbucket.org/1.0/repositories/#{$Config[:bitbucket][:user]}/#{app.dir_name}")
120
+ puts "#{'Removed'.format(:green,:bold)}" + " #{app.dir_name}"
121
+ rescue
122
+ puts "#{'Already Removed'.format(:green,:bold)}" + " #{app.dir_name}"
123
+ end
124
+ end
125
+
126
+ puts "\n---------------------------------------------------------------------------------------------------------------"
127
+ puts 'DELETING POW DOMAINS...'
128
+ Run.pow_destroy(app, app.root_domain)
129
+ Run.pow_destroy(app, Fanforce.default_short_domain)
130
+
131
+ puts "\n---------------------------------------------------------------------------------------------------------------"
132
+ puts 'DELETING FILES...'
133
+ if File.directory?(app_dir)
134
+ FileUtils.rm_rf(app_dir)
135
+ puts "#{'Removed'.format(:bold, :green)} #{app_dir_name}/"
136
+ else
137
+ puts "#{'Already Removed'.format(:bold, :green)} #{app_dir_name}/"
138
+ end
139
+
140
+ puts "\n---------------------------------------------------------------------------------------------------------------"
141
+ puts 'DONE! (note: iron workers were not deleted)'
142
+ puts '---------------------------------------------------------------------------------------------------------------'
143
+
144
+ end
145
+
146
+ ######################################################################################################################
147
+
148
+ def run_update(app_dir, processed_count, total_count)
149
+ app = App.load(app_dir)
150
+ puts "\n---------------------------------------------------------------------------------------------------------------"
151
+ puts "#{'app'.upcase.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
152
+
153
+ Dir.chdir(app_dir) do
154
+ puts "\nUPDATING FILES..."
155
+ setup_files(app)
156
+
157
+ puts "\nRUNNING BUNDLER..."
158
+ Run.bundle_install(app.dir)
159
+
160
+ puts "\nUPDATING POW DOMAINS..."
161
+ setup_pow(app)
162
+
163
+ puts "\nUPDATING LOCAL GIT REPOSITORY..."
164
+ setup_local_git(app)
165
+
166
+ puts "\nUPDATING ENV VARIABLES..."
167
+ setup_envs(app, :development)
168
+
169
+ print "\nRESTARTING POW... "
170
+ restart(app, :development)
171
+ puts 'DONE'
172
+ end
173
+
174
+ end
175
+
176
+ ######################################################################################################################
177
+
178
+ def run_push(app_dir, processed_count, total_count, environment, command)
179
+ app = App.load(app_dir)
180
+ puts "\n---------------------------------------------------------------------------------------------------------------"
181
+ puts "#{'app'.upcase.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
182
+
183
+ Dir.chdir(app_dir) do
184
+ if [:all,:bitbucket].include?(command) and $Config[:bitbucket].present?
185
+ if !(`git remote`).split(/\r?\n/).include?('bitbucket')
186
+ setup_bitbucket(app)
187
+ else
188
+ puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Bitbucket (#{$Config[:bitbucket][:user]})..."
189
+ Run.command('git push bitbucket --all')
190
+ end
191
+ end
192
+
193
+ environments = (environment==:all) ? [:staging,:production] : [environment]
194
+ environments.each do |environment|
195
+ if [:all,:heroku].include?(command)
196
+ remote_name = "#{environment==:staging ? 'stg' : 'prd'}-heroku"
197
+ setup_heroku(app, environment) if !(`git remote`).split(/\r?\n/).include?(remote_name)
198
+
199
+ vars = Env.vars_by_app(environment)[app.dir_name] || {}
200
+ puts "\n#{"Updating Env Vars".format(:green,:bold)} on Heroku #{environment.to_s.titleize} (#{vars.size} variables)..."
201
+ push_env_to(environment, app, vars)
202
+
203
+ puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Heroku #{environment.to_s.titleize} (#{remote_name})..."
204
+ Run.command("git push #{remote_name} master")
205
+ end
206
+
207
+ if [:all,:iron].include?(command)
208
+ puts ''
209
+ upload_iron(app, command, [environment])
210
+ end
211
+ end
212
+
213
+ end
214
+ end
215
+
216
+ ######################################################################################################################
217
+
218
+ def count
219
+ puts "\n---------------------------------------------------------------------------------------------------------------"
220
+ puts "#{Apps.count} APPS".format(:bold,:green) + ' IN CURRENT DIRECTORY'
221
+ puts '---------------------------------------------------------------------------------------------------------------'
222
+ puts ''
223
+ end
224
+
225
+ ######################################################################################################################
226
+
227
+ def run_restart(app_dir, processed_count, total_count, environment)
228
+ app = App.load(app_dir)
229
+ puts "---------------------------------------------------------------------------------------------------------------"
230
+ Dir.chdir(app_dir) do
231
+ if [:all, :development].include?(environment)
232
+ puts "#{'DEVELOPMENT '.format(:bold)}#{app.dir_name.format(:green)} restarted" if restart(app, :development)
233
+ end
234
+ if [:all, :staging].include?(environment)
235
+ puts "#{'STAGING '.format(:bold)}#{app.dir_name.format(:green)} restarted" if restart(app, :staging)
236
+ end
237
+ if [:all, :production].include?(environment)
238
+ puts "#{'PRODUCTION '.format(:bold)}#{app.dir_name.format(:green)} restarted" if restart(app, :production)
239
+ end
240
+ end
241
+ end
242
+
243
+ def restart(app, environment)
244
+ if environment == :development
245
+ File.mkdir("#{app.dir}/tmp") if !File.directory?("#{app.dir}/tmp")
246
+ FileUtils.touch("#{app.dir}/tmp/restart.txt")
247
+ elsif [:production, :staging].include?(environment)
248
+ if $Config[:heroku].blank? or $Config[:heroku][environment].blank?
249
+ puts "#{'OOPS...'.format(:red,:bold)} #{environment} has not been setup on heroku"
250
+ return false
251
+ end
252
+ heroku = auth_heroku(environment)
253
+ heroku.post_ps_restart get_heroku_app_name(app, environment)
254
+ end
255
+ return true
256
+ end
257
+
258
+ ######################################################################################################################
259
+
260
+ def run_bundle(app_dir, processed_count, total_count, arg, extra_args)
261
+ app = App.load(app_dir)
262
+ puts "\n---------------------------------------------------------------------------------------------------------------"
263
+ puts "#{'app'.upcase.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
264
+
265
+ Dir.chdir(app_dir) do
266
+ if Gem::Specification::find_all_by_name('bundler').empty?
267
+ puts 'Installing Bundler... '
268
+ `gem install bundler`
269
+ puts 'DONE'
270
+ end
271
+
272
+ app.update_file(:gemfile)
273
+ Run.command("bundle #{arg} #{extra_args.join(' ')}")
274
+ restart(app, :development)
275
+ puts 'DONE'.format(:green)
276
+ end
277
+ end
278
+
279
+ ######################################################################################################################
280
+
281
+ def run_cleanorgs(app_dir, processed_count, total_count, environment, supercore_api_key)
282
+ ENV['RACK_ENV'] = environment.to_s
283
+ app = App.load(app_dir)
284
+ puts "\n---------------------------------------------------------------------------------------------------------------"
285
+ puts "#{'app'.upcase.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
286
+
287
+ require 'redis'
288
+ require 'fanforce/api'
289
+ ff = Fanforce::API.new(supercore_api_key)
290
+
291
+ Dir.chdir(app_dir) do
292
+ app = App.load(app_dir)
293
+ vars = Env.vars_by_app(environment)[app.dir_name] || {}
294
+ redis = Redis.new(url: vars['REDIS_URL'])
295
+
296
+ installs = redis.keys("installed:#{app.dir_name}:*")
297
+ organizations = {}
298
+ redis.multi do
299
+ organizations = installs.inject({}) do |result, key|
300
+ next result if key !~ /^(installed:#{app.dir_name}:(.+))$/
301
+ result.update $2 => redis.get($1)
302
+ end
303
+ end
304
+ puts "#{organizations.size} installs found..."
305
+ processed_count = 0
306
+ organizations.each do |organization_id, api_key|
307
+ print "- checking organization #{processed_count+=1}... "
308
+ if ff.get("/organizations/#{organization_id}", fields: '_id')
309
+ puts 'VALID'
310
+ else
311
+ print 'INVALID... '
312
+ redis.del("installed:#{app.dir_name}:#{organization_id}")
313
+ puts 'UNINSTALLED'
314
+ end
315
+ end
316
+
317
+ end
318
+ end
319
+
320
+ ######################################################################################################################
321
+
322
+ def preprocess_git_overview
323
+ puts ''
324
+ length = Apps.dir_names.inject(0) {|length, dir_name| dir_name.length > length ? dir_name.length : length }
325
+ puts sprintf("%-#{length+3}s %-20s %s", 'Directory', 'Plugin Type', 'Status').format(:bold)
326
+ length
327
+ end
328
+
329
+ def postprocess_git_overview
330
+ puts '------------------------------------------------------------------------'
331
+ puts 'DONE'
332
+ end
333
+
334
+ def run_git_overview(app_dir, processed_count, total_count, length)
335
+ app = App.load(app_dir)
336
+ puts '------------------------------------------------------------------------'
337
+ Dir.chdir(app_dir) do
338
+ committed = `git status`.include?('nothing to commit') ? true : false
339
+ printf "%-#{length+3}s %s\n", app.dir_name, committed ? 'Committed'.format(:green) : 'Uncommitted'.format(:red)
340
+ end
341
+ end
342
+
343
+ def run_git(app_dir, processed_count, total_count, extra_args)
344
+ app = App.load(app_dir)
345
+ puts "\n---------------------------------------------------------------------------------------------------------------"
346
+ puts "#{'app'.upcase.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
347
+
348
+ extra_args = extra_args.map {|c| c.include?(' ') ? c.to_json : c }.join(' ')
349
+ extra_args = '--no-pager ' + extra_args if extra_args !~ /--no-pager/
350
+
351
+ Dir.chdir(app_dir) do
352
+ Run.command("git #{extra_args}")
353
+ puts 'DONE'.format(:green)
354
+ end
355
+ end
356
+
357
+ ######################################################################################################################
358
+
359
+ def run_iron(app_dir, processed_count, total_count, command, environment)
360
+ environments = environment == :all ? [:development, :staging, :production] : [environment]
361
+ app = App.load(app_dir)
362
+ puts "\n---------------------------------------------------------------------------------------------------------------"
363
+ puts "#{'app'.upcase.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
364
+
365
+ upload_iron(app, command, environments)
366
+ end
367
+
368
+ def upload_iron(app, command, environments)
369
+ if !File.directory?("#{app.dir}/workers")
370
+ return puts "#{'Skipped '.format(:bold)} no workers folder was found"
371
+ end
372
+
373
+ environments.each do |environment|
374
+ vars = Env.vars_by_app(environment)[app.dir_name] || {}
375
+ next puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} is missing IRON_TOKEN and/or IRON_PROJECT_ID env variables" if vars['IRON_TOKEN'].blank? or vars['IRON_PROJECT_ID'].blank?
376
+
377
+ puts "#{'Updating Env'.format(:green,:bold)} #{environment.to_s.titleize}... and workers have #{vars.size} env variables"
378
+ push_env_to(environment, app, vars, true)
379
+
380
+ iron_worker = IronWorkerNG::Client.new(:token => vars['IRON_TOKEN'], :project_id => vars['IRON_PROJECT_ID'])
381
+ Dir.chdir("#{app.dir}/workers") do
382
+ workers = Dir['*.worker']
383
+ next puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} has 0 workers" if workers.size == 0
384
+
385
+ upload_processes = []
386
+ FileUtils.cp("#{app.dir}/workers/.env/#{environment}.rb", "#{app.dir}/workers/.env/.#{environment}env.rb")
387
+ workers.each do |filename|
388
+ code_name = filename.gsub('.worker', '')
389
+ remove_single_worker(code_name, iron_worker, environment) if command == :reset
390
+
391
+ puts "#{'Uploading'.format(:green,:bold)} #{filename.gsub('.worker', '')} to #{environment.to_s.titleize}..."
392
+ code = IronWorkerNG::Code::Base.new(:workerfile => "#{app.dir}/workers/#{filename}")
393
+ code.remote
394
+ code.name = code_name
395
+ code.file("#{app.dir}/workers/.env/.#{environment}env.rb")
396
+
397
+ upload_processes << upload_iron_worker(app, iron_worker, code, filename, environment)
398
+ end
399
+ upload_processes.each { |pid| Process.waitpid(pid) }
400
+ FileUtils.remove_file("#{app.dir}/workers/.env/.#{environment}env.rb")
401
+ end
402
+ end
403
+ end
404
+
405
+ def upload_iron_worker(app, iron_worker, code, filename, environment)
406
+ fork do
407
+ begin
408
+ iron_worker.codes.create(code, max_concurrency: 5)
409
+ rescue Exception => e
410
+ puts "#{'Aborted '.format(:red,:bold)} upload of #{filename.gsub('.worker', '')} to #{environment.to_s.titleize}..."
411
+ puts e.message
412
+ puts e.backtrace
413
+ puts ''
414
+ end
415
+ end
416
+ end
417
+
418
+ def remove_single_worker(code_name, iron_worker, environment)
419
+ iron_worker.codes.list.each do |code|
420
+ next if code.name != code_name
421
+ iron_worker.codes.delete(code.id)
422
+ puts "#{'Removing '.format(:green,:bold)} #{code_name} from #{environment.to_s.titleize}..."
423
+ return true
424
+ end
425
+ end
426
+
427
+ ######################################################################################################################
428
+
429
+ def delete_all_iron_workers(environment)
430
+ puts ''
431
+ environments = environment == :all ? [:development, :staging, :production] : [environment]
432
+
433
+ iron_auths = {}
434
+ Apps.each do |app, cur_count, total|
435
+ environments.each do |environment|
436
+ vars = Env.vars_by_app(environment)[app.dir_name]
437
+ iron_auths[environment] ||= {}
438
+ iron_auths[environment][vars['IRON_PROJECT_ID']] = vars['IRON_TOKEN'] if vars['IRON_PROJECT_ID'].present?
439
+ end
440
+ end
441
+
442
+ environments.each do |environment|
443
+ puts '---------------------------------------------------------------------------------------------------------------'
444
+ puts "REMOVING WORKERS IN #{environment.to_s.upcase}..."
445
+
446
+ workers_found = false
447
+ iron_auths[environment].each do |iron_project_id, iron_token|
448
+ iron_worker = IronWorkerNG::Client.new(:token => iron_token, :project_id => iron_project_id)
449
+ iron_worker.codes.list.each do |code|
450
+ workers_found = true
451
+ iron_worker.codes.delete(code.id)
452
+ puts "#{'Removed'.format(:red,:bold)} #{code.name}"
453
+ end
454
+ end
455
+ puts 'No workers were found' if !workers_found
456
+ end
457
+
458
+ puts '---------------------------------------------------------------------------------------------------------------'
459
+ end
460
+
461
+ ######################################################################################################################
462
+ def get_heroku_app_qa_name(app, environment)
463
+ heroku_app_name = "#{environment==:production ? 'prd' : 'qa'}-#{app.dir_name}"
464
+ heroku_app_name.length > 30 ? heroku_app_name.gsub!(/(a|e|i|o|u)/, '') : heroku_app_name
465
+ end
466
+
467
+ def run_upgrade(app_dir, processed_count, total_count)
468
+ environment = :qa
469
+ app = App.load(app_dir)
470
+ puts "\n---------------------------------------------------------------------------------------------------------------"
471
+ puts "#{'app'.upcase.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
472
+
473
+ #heroku = auth_heroku(:staging)
474
+ #heroku_app_name = get_heroku_app_qa_name(app, environment)
475
+ #begin
476
+ # heroku.delete_app(heroku_app_name)
477
+ # puts "#{'Deleted '.format(:green,:bold)}" + "#{environment} app on heroku (#{heroku_app_name})"
478
+ #rescue
479
+ # heroku.post_app(name: heroku_app_name)
480
+ # puts "#{'Not Found '.format(:green,:bold)}" + "#{environment} on heroku (#{heroku_app_name})"
481
+ #end
482
+
483
+ if (`git remote`).split(/\r?\n/).include?($Config[:bitbucket][:user])
484
+ puts "#{'Removed '.format(:red,:bold)}" + "git remote for #{$Config[:bitbucket][:user]}"
485
+ `git remote rm #{$Config[:bitbucket][:user]}`
486
+ end
487
+ if (`git remote`).split(/\r?\n/).include?('qa-heroku')
488
+ puts "#{'Removed '.format(:red,:bold)}" + "git remote for qa-heroku"
489
+ `git remote rm qa-heroku`
490
+ end
491
+ if (`git remote`).split(/\r?\n/).include?('bitbucket')
492
+ puts "#{'Updated '.format(:green,:bold)}" + "git remote for bitbucket"
493
+ `git remote rm bitbucket`
494
+ `git remote add bitbucket git@bitbucket.org:#{$Config[:bitbucket][:user]}/#{app.dir_name}.git`
495
+ else
496
+ `git remote add bitbucket git@bitbucket.org:#{$Config[:bitbucket][:user]}/#{app.dir_name}.git`
497
+ puts "#{'Created '.format(:green,:bold)}" + "git remote for bitbucket"
498
+ end
499
+
500
+ `git config --remove-section branch.master`
501
+ `git push --set-upstream bitbucket master`
502
+
503
+ end
504
+
505
+
506
+ end