brightpearl-cli 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/bin/bp +1 -1
- data/bin/brightpearl +1 -1
- data/lib/brightpearl_cli.rb +161 -168
- data/lib/core/api.rb +1 -1
- data/lib/core/config.rb +10 -133
- data/lib/core/config_unique.rb +113 -0
- data/lib/core/encrypter.rb +6 -6
- data/lib/core/enums.rb +1 -1
- data/lib/core/git.rb +123 -108
- data/lib/core/git_delete.rb +89 -0
- data/lib/core/jira.rb +2 -2
- data/lib/core/mysql.rb +14 -14
- data/lib/core/pom.rb +129 -0
- data/lib/core/terminal.rb +28 -8
- data/lib/core/tools.rb +6 -6
- data/lib/core/utils_files.rb +92 -0
- data/lib/core/utils_routes.rb +25 -0
- data/lib/core/utils_strings.rb +45 -0
- data/lib/core/validate.rb +1 -1
- data/lib/routes/build.rb +16 -17
- data/lib/routes/dummy_order.rb +5 -5
- data/lib/routes/fix.rb +49 -0
- data/lib/routes/git_branch.rb +6 -6
- data/lib/routes/git_checkout.rb +42 -33
- data/lib/routes/git_delete.rb +8 -62
- data/lib/routes/git_merge.rb +198 -111
- data/lib/routes/git_pull.rb +11 -11
- data/lib/routes/git_push.rb +21 -12
- data/lib/routes/git_stash.rb +13 -8
- data/lib/routes/git_update.rb +17 -22
- data/lib/routes/jira.rb +3 -3
- data/lib/routes/production_logs.rb +12 -12
- data/lib/routes/reset.rb +1 -1
- data/lib/routes/review.rb +6 -5
- data/lib/routes/scripts_api_docs.rb +5 -5
- data/lib/routes/scripts_branch_cleaner.rb +58 -79
- data/lib/routes/scripts_color.rb +1 -1
- data/lib/routes/scripts_pom_fixer.rb +5 -62
- data/lib/routes/scripts_sonar.rb +82 -0
- data/lib/routes/setup.rb +6 -6
- data/lib/routes/tail.rb +5 -5
- data/lib/routes/test.rb +3 -3
- data/lib/routes/update.rb +1 -1
- metadata +16 -9
- data/lib/routes/scripts_code_sniffer.rb +0 -36
data/lib/core/git.rb
CHANGED
@@ -2,7 +2,7 @@ require 'columnist'
|
|
2
2
|
require 'date'
|
3
3
|
require 'highline'
|
4
4
|
|
5
|
-
module
|
5
|
+
module App
|
6
6
|
|
7
7
|
class Git
|
8
8
|
|
@@ -19,7 +19,7 @@ module Brightpearl
|
|
19
19
|
DB = 'db'
|
20
20
|
|
21
21
|
MERGED_PREFIX = 'MERGED-'
|
22
|
-
MDASH = '
|
22
|
+
MDASH = '━'
|
23
23
|
|
24
24
|
MASTER = 'master'
|
25
25
|
REFNAME = 'refname'
|
@@ -81,7 +81,7 @@ module Brightpearl
|
|
81
81
|
end
|
82
82
|
repos.each do |repo_dir_inner|
|
83
83
|
unless File.directory?(repo_dir_inner)
|
84
|
-
|
84
|
+
App::Terminal::error('Directory not found', "Directory doesn't exist: #{App::Terminal::format_directory(repo_dir_inner)}", true)
|
85
85
|
end
|
86
86
|
raw_terminal_output = `
|
87
87
|
cd #{repo_dir_inner} &&
|
@@ -110,7 +110,7 @@ module Brightpearl
|
|
110
110
|
branches["#{data[:"#{COMMITTER_DATE}"].strftime('%Y-%m-%d-%H-%I-%S')}-#{branch_count}"] = data
|
111
111
|
branch_count = branch_count + 1
|
112
112
|
else
|
113
|
-
|
113
|
+
App::Terminal::error('Sort not supported', "The following sorting option is not yet supported: #{sort}", true)
|
114
114
|
end
|
115
115
|
end
|
116
116
|
branch_keys = branches.keys
|
@@ -121,7 +121,7 @@ module Brightpearl
|
|
121
121
|
branch_keys.sort_by! { |value| value }
|
122
122
|
branch_keys = branch_keys.reverse
|
123
123
|
else
|
124
|
-
|
124
|
+
App::Terminal::error('Sort not supported', "The following sorting option is not yet supported: #{sort}", true)
|
125
125
|
end
|
126
126
|
branch_data = []
|
127
127
|
branch_keys.each do |key|
|
@@ -152,7 +152,7 @@ module Brightpearl
|
|
152
152
|
end
|
153
153
|
repos.each do |repo_dir_inner|
|
154
154
|
unless File.directory?(repo_dir_inner)
|
155
|
-
|
155
|
+
App::Terminal::error('Directory not found', "Directory doesn't exist: #{App::Terminal::format_directory(repo_dir)}", true)
|
156
156
|
end
|
157
157
|
update_origin(repo_dir_inner)
|
158
158
|
raw_terminal_output = `
|
@@ -176,7 +176,7 @@ module Brightpearl
|
|
176
176
|
branches["#{data[:"#{COMMITTER_DATE}"].strftime('%Y-%m-%d-%H-%I-%S')}-#{branch_count}"] = data
|
177
177
|
branch_count = branch_count + 1
|
178
178
|
else
|
179
|
-
|
179
|
+
App::Terminal::error('Sort not supported', "The following sorting option is not yet supported: #{sort}", true)
|
180
180
|
end
|
181
181
|
end
|
182
182
|
branch_keys = branches.keys
|
@@ -187,7 +187,7 @@ module Brightpearl
|
|
187
187
|
branch_keys.sort_by! { |value| value }
|
188
188
|
branch_keys = branch_keys.reverse
|
189
189
|
else
|
190
|
-
|
190
|
+
App::Terminal::error('Sort not supported', "The following sorting option is not yet supported: #{sort}", true)
|
191
191
|
end
|
192
192
|
branch_data = []
|
193
193
|
branch_keys.each do |key|
|
@@ -215,7 +215,7 @@ module Brightpearl
|
|
215
215
|
return @branches_as_array[:remote_both] if @branches_as_array[:remote_both] != nil
|
216
216
|
end
|
217
217
|
else
|
218
|
-
if repo_dir ==
|
218
|
+
if repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)
|
219
219
|
if local_remote == LOCAL
|
220
220
|
return @branches_as_array[:local_code] if @branches_as_array[:local_code] != nil
|
221
221
|
else
|
@@ -263,7 +263,7 @@ module Brightpearl
|
|
263
263
|
return @branches_as_array[:remote_both] = repos_to_return[0], repos_to_return[1]
|
264
264
|
end
|
265
265
|
else
|
266
|
-
if repo_dir ==
|
266
|
+
if repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)
|
267
267
|
if local_remote == LOCAL
|
268
268
|
return @branches_as_array[:local_code] = repos_to_return[0]
|
269
269
|
else
|
@@ -283,8 +283,8 @@ module Brightpearl
|
|
283
283
|
# @return Array
|
284
284
|
def get_all_branches_as_array
|
285
285
|
unless @branches_as_array_all
|
286
|
-
local_branches = get_branches_as_array(
|
287
|
-
remote_branches = get_branches_as_array(
|
286
|
+
local_branches = get_branches_as_array(App::Git::LOCAL)
|
287
|
+
remote_branches = get_branches_as_array(App::Git::REMOTE)
|
288
288
|
@branches_as_array_all = local_branches[0].concat(local_branches[1]).concat(remote_branches[0]).concat(remote_branches[1])
|
289
289
|
@branches_as_array_all.uniq!
|
290
290
|
@branches_as_array_all.sort_by! { |m| m.downcase }
|
@@ -315,10 +315,10 @@ module Brightpearl
|
|
315
315
|
# Draws the actual table of branches.
|
316
316
|
# @return void
|
317
317
|
def show_branches_draw_table(brightpearl_code, brightpearl_db)
|
318
|
-
current_code_branch = current_branch_for_repo(
|
319
|
-
current_db_branch = current_branch_for_repo(
|
318
|
+
current_code_branch = current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
319
|
+
current_db_branch = current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
|
320
320
|
column_width = [2, 20, 23, 15, 34, 1, 34, 15, 23, 20, 1]
|
321
|
-
|
321
|
+
App::Tools::validate_report_width(column_width)
|
322
322
|
puts "\n"
|
323
323
|
table(:border => false) do
|
324
324
|
row do
|
@@ -345,7 +345,7 @@ module Brightpearl
|
|
345
345
|
row do
|
346
346
|
code_accent, code_color, code_star, db_accent, db_color, db_star = show_branches_get_colors(code_branch, current_code_branch, current_db_branch, db_branch)
|
347
347
|
column("#{code_star}", :color => code_color)
|
348
|
-
column(
|
348
|
+
column(App::Tools::time_passed_since(code_time_adjusted), :color => code_color)
|
349
349
|
column(code_branch[:"#{COMMITTER_NAME}"], :color => code_color)
|
350
350
|
column(code_branch[:"#{COMMITTER_DATE}"].strftime('%d %^b %H:%M'), :color => code_color)
|
351
351
|
column(code_branch[:"#{REFNAME}"], :color => code_accent)
|
@@ -353,7 +353,7 @@ module Brightpearl
|
|
353
353
|
column(db_branch[:"#{REFNAME}"], :color => db_accent)
|
354
354
|
column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH : db_branch[:"#{COMMITTER_DATE}"].strftime('%d %^b %H:%M'), :color => db_color)
|
355
355
|
column(db_branch[:"#{COMMITTER_NAME}"], :color => db_color)
|
356
|
-
column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH :
|
356
|
+
column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH : App::Tools::time_passed_since(db_branch[:"#{COMMITTER_DATE}"] - (1 / 24.0)), :color => db_color)
|
357
357
|
column("#{db_star}", :color => db_color)
|
358
358
|
end
|
359
359
|
end
|
@@ -370,7 +370,7 @@ module Brightpearl
|
|
370
370
|
column(db_branch[:"#{REFNAME}"], :color => db_accent)
|
371
371
|
column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH : db_branch[:"#{COMMITTER_DATE}"].strftime('%d %^b %H:%M'), :color => db_color)
|
372
372
|
column(db_branch[:"#{COMMITTER_NAME}"], :color => db_color)
|
373
|
-
column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH :
|
373
|
+
column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH : App::Tools::time_passed_since(db_branch[:"#{COMMITTER_DATE}"]), :color => db_color)
|
374
374
|
column('')
|
375
375
|
end
|
376
376
|
end
|
@@ -426,17 +426,17 @@ module Brightpearl
|
|
426
426
|
# @return void
|
427
427
|
def show_branches_divider(column_width, color = 'white')
|
428
428
|
row do
|
429
|
-
column(
|
430
|
-
column(
|
431
|
-
column(
|
432
|
-
column(
|
433
|
-
column(
|
434
|
-
column(
|
435
|
-
column(
|
436
|
-
column(
|
437
|
-
column(
|
438
|
-
column(
|
439
|
-
column(
|
429
|
+
column(App::Terminal::fill(column_width[0], MDASH), :color => color)
|
430
|
+
column(App::Terminal::fill(column_width[1], MDASH), :color => color)
|
431
|
+
column(App::Terminal::fill(column_width[2], MDASH), :color => color)
|
432
|
+
column(App::Terminal::fill(column_width[3], MDASH), :color => color)
|
433
|
+
column(App::Terminal::fill(column_width[4], MDASH), :color => color)
|
434
|
+
column(App::Terminal::fill(column_width[5], MDASH), :color => color)
|
435
|
+
column(App::Terminal::fill(column_width[6], MDASH), :color => color)
|
436
|
+
column(App::Terminal::fill(column_width[7], MDASH), :color => color)
|
437
|
+
column(App::Terminal::fill(column_width[8], MDASH), :color => color)
|
438
|
+
column(App::Terminal::fill(column_width[9], MDASH), :color => color)
|
439
|
+
column(App::Terminal::fill(column_width[10], MDASH), :color => color)
|
440
440
|
end
|
441
441
|
end
|
442
442
|
|
@@ -451,23 +451,23 @@ module Brightpearl
|
|
451
451
|
# @return void
|
452
452
|
def update_origin(repo_dir = nil)
|
453
453
|
validate_repo_dir(repo_dir)
|
454
|
-
unless @origin_updated_code && repo_dir ==
|
455
|
-
@origin_updated_db && repo_dir ==
|
454
|
+
unless @origin_updated_code && repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE) ||
|
455
|
+
@origin_updated_db && repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB) ||
|
456
456
|
@origin_updated_code && @origin_updated_db && repo_dir.nil?
|
457
457
|
|
458
|
-
|
458
|
+
App::Terminal::output("Updating origin (#{get_repo_shorthand(repo_dir)})")
|
459
459
|
case repo_dir
|
460
|
-
when
|
460
|
+
when App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)
|
461
461
|
@origin_updated_code = true
|
462
|
-
|
463
|
-
when
|
462
|
+
App::Terminal::command(['git fetch -p'], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
463
|
+
when App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)
|
464
464
|
@origin_updated_db = true
|
465
|
-
|
465
|
+
App::Terminal::command(['git fetch -p'], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
|
466
466
|
else
|
467
467
|
@origin_updated_code = true
|
468
468
|
@origin_updated_db = true
|
469
469
|
repo_loop.each do |repo_dir_inner|
|
470
|
-
|
470
|
+
App::Terminal::command(['git fetch -p'], repo_dir_inner)
|
471
471
|
end
|
472
472
|
end
|
473
473
|
end
|
@@ -478,13 +478,13 @@ module Brightpearl
|
|
478
478
|
# @return void
|
479
479
|
def merge_master_into_current_branch(repo_dir, push_to_origin = true)
|
480
480
|
current_branch = current_branch_for_repo(repo_dir)
|
481
|
-
if current_branch ==
|
481
|
+
if current_branch == App::Git::MASTER
|
482
482
|
return
|
483
483
|
end
|
484
484
|
commands = Array.new
|
485
485
|
commands << 'git checkout master'
|
486
486
|
commands << 'git pull'
|
487
|
-
if current_branch !=
|
487
|
+
if current_branch != App::Git::MASTER
|
488
488
|
commands << "git checkout #{current_branch}"
|
489
489
|
commands << 'git pull'
|
490
490
|
commands << 'git merge master'
|
@@ -492,7 +492,7 @@ module Brightpearl
|
|
492
492
|
if push_to_origin
|
493
493
|
commands << 'git push'
|
494
494
|
end
|
495
|
-
|
495
|
+
App::Terminal::command(commands, repo_dir)
|
496
496
|
end
|
497
497
|
|
498
498
|
# Makes sure that both BP-CODE & BP-DB are on the same branch.
|
@@ -518,24 +518,25 @@ module Brightpearl
|
|
518
518
|
end
|
519
519
|
|
520
520
|
# Checks if you have staged changes in current repo and if so, prompts to stash them.
|
521
|
+
# @param force_stash_message -- If a string is passed, will be displayed as the "FORCE STASH WARNING" and a stash will be enforced.
|
521
522
|
# @return void
|
522
523
|
def check_for_uncommitted_files(automatic = false, force_stash_message = false)
|
523
524
|
repo_loop.each do |repo_dir|
|
524
525
|
results = `cd #{repo_dir} && git status | grep 'Changes '`
|
525
526
|
results = results.split("\n")
|
526
527
|
if results.any?
|
527
|
-
|
528
|
+
App::Terminal::command(['git status'], repo_dir)
|
528
529
|
current_branch = current_branch_for_repo(repo_dir)
|
529
|
-
if automatic ||
|
530
|
-
|
531
|
-
|
530
|
+
if automatic || App::Terminal::prompt_yes_no("Found uncommitted files on branch #{App::Terminal::format_branch(current_branch)}", nil, "Would you like to #{App::Terminal::format_action('stash')}\x1B[38;5;89m these changes before continuing?")
|
531
|
+
App::Terminal::output('Stashing working changes', App::Terminal::MSG_AUTOMATIC) if automatic
|
532
|
+
App::Terminal::command('git stash', repo_dir)
|
532
533
|
else
|
533
534
|
if force_stash_message != false
|
534
535
|
abort_message = force_stash_message.is_a?(String) ? force_stash_message : nil
|
535
|
-
|
536
|
+
App::Terminal::abort(abort_message,["In this particular scenario, you #{App::Terminal::format_invalid('cannot continue', true)} unless you stash your changes."], true, false)
|
536
537
|
end
|
537
|
-
unless
|
538
|
-
|
538
|
+
unless App::Terminal::prompt_yes_no('Continue without stashing?', "By selecting #{App::Terminal::format_action('Yes')}\x1B[38;5;240m, you're changes will be carried over to the next branch.", nil, false)
|
539
|
+
App::Terminal::abort(nil, nil, true, false)
|
539
540
|
end
|
540
541
|
end
|
541
542
|
end
|
@@ -555,14 +556,14 @@ module Brightpearl
|
|
555
556
|
stashes_to_skip = 0
|
556
557
|
while results.any?
|
557
558
|
stash_name = results[0].split(/:/).first
|
558
|
-
if automatic ||
|
559
|
-
|
560
|
-
stash_apply_successful =
|
559
|
+
if automatic || App::Terminal::prompt_yes_no("Found the following stash on #{App::Terminal::format_branch(current_branch_for_repo(repo_dir))}", "#{results[0]}", "Would you like to #{App::Terminal::format_action('apply')}\x1B[38;5;89m this stash now?")
|
560
|
+
App::Terminal::output('Un-stashing working changes', App::Terminal::MSG_AUTOMATIC) if automatic
|
561
|
+
stash_apply_successful = App::Terminal::command(["git stash apply #{stash_name}"], repo_dir)
|
561
562
|
if stash_apply_successful[0] == true
|
562
|
-
|
563
|
+
App::Terminal::command("git stash drop #{stash_name}", repo_dir)
|
563
564
|
results = check_for_stash_get_stashes(repo_dir)
|
564
565
|
else
|
565
|
-
|
566
|
+
App::Terminal::error("Stash could not be applied successfully (and therefore wasn't dropped).", ["#{results[0]}", nil, "Please #{App::Terminal::format_action('open an IDE')} and resolve your conflicts before continuing.", "Don't forget to drop your stash afterwards with: #{App::Terminal::format_command("git stash drop #{stash_name}")}"], false)
|
566
567
|
results = []
|
567
568
|
end
|
568
569
|
else
|
@@ -588,27 +589,29 @@ module Brightpearl
|
|
588
589
|
end
|
589
590
|
|
590
591
|
# Checks if both repos are on same branch and displays either ERROR or WARNING.
|
591
|
-
# @return
|
592
|
+
# @return boolean -- TRUE if same branch, FALSE if not.
|
592
593
|
def check_for_same_branch(display = SAME_BRANCH_WARNING)
|
593
|
-
branch_code = current_branch_for_repo(
|
594
|
-
branch_db = current_branch_for_repo(
|
594
|
+
branch_code = current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
595
|
+
branch_db = current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
|
595
596
|
if branch_code != branch_db
|
596
597
|
case display
|
597
598
|
when SAME_BRANCH_WARNING
|
598
|
-
|
599
|
-
"#{
|
600
|
-
"#{
|
599
|
+
App::Terminal::warning("You're on #{App::Terminal::format_highlight('2 different branches')}", [
|
600
|
+
"#{App::Terminal::format_directory(get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))} is on #{App::Terminal::format_branch(branch_code)}",
|
601
|
+
"#{App::Terminal::format_directory(get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))} is on #{App::Terminal::format_branch(branch_db)}"
|
601
602
|
])
|
602
603
|
when SAME_BRANCH_ERROR
|
603
604
|
else
|
604
|
-
|
605
|
-
"#{
|
606
|
-
"#{
|
605
|
+
App::Terminal::error("You're on #{App::Terminal::format_highlight('2 different branches')}", [
|
606
|
+
"#{App::Terminal::format_directory(get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))} is on #{App::Terminal::format_branch(branch_code)}",
|
607
|
+
"#{App::Terminal::format_directory(get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))} is on #{App::Terminal::format_branch(branch_db)}",
|
607
608
|
nil,
|
608
609
|
'You cannot run this command unless both of your repos are on the same branch.'
|
609
610
|
])
|
610
611
|
end
|
612
|
+
return false
|
611
613
|
end
|
614
|
+
true
|
612
615
|
end
|
613
616
|
|
614
617
|
# Returns an array that include info for BOTH repos. Finds out whether a branch exists and if it's current or not
|
@@ -621,18 +624,18 @@ module Brightpearl
|
|
621
624
|
validate_code_db(code_db)
|
622
625
|
case code_db
|
623
626
|
when CODE
|
624
|
-
if repo_dir ==
|
627
|
+
if repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)
|
625
628
|
data << nil
|
626
629
|
next
|
627
630
|
end
|
628
631
|
else
|
629
|
-
if repo_dir ==
|
632
|
+
if repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)
|
630
633
|
data << nil
|
631
634
|
next
|
632
635
|
end
|
633
636
|
end
|
634
637
|
end
|
635
|
-
|
638
|
+
App::Terminal::output("Retrieving branch data for #{App::Terminal::format_branch(branch_name)} \xe2\x80\x94 (#{get_repo_shorthand(repo_dir)})")
|
636
639
|
repo_data = {}
|
637
640
|
repo_data
|
638
641
|
repo_data[:"#{BRANCH_NAME}"] = branch_name
|
@@ -650,12 +653,12 @@ module Brightpearl
|
|
650
653
|
repo_data[:"#{BRANCH_IS_UP_TO_DATE}"] = nil
|
651
654
|
end
|
652
655
|
# Check branch exists
|
653
|
-
unless branch_exists(branch_name, repo_dir,
|
656
|
+
unless branch_exists(branch_name, repo_dir, App::Git::LOCAL)
|
654
657
|
repo_data[:"#{BRANCH_EXISTS_LOCALLY}"] = false
|
655
|
-
|
656
|
-
|
657
|
-
unless branch_exists(branch_name, repo_dir,
|
658
|
-
|
658
|
+
App::Terminal::output("Branch #{App::Terminal::format_branch(branch_name)} not found #{App::Terminal::format_action('locally')} in #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))}", App::Terminal::MSG_WARNING) if verbose
|
659
|
+
App::Terminal::output('Checking origin') if verbose
|
660
|
+
unless branch_exists(branch_name, repo_dir, App::Git::REMOTE)
|
661
|
+
App::Terminal::output("Branch #{App::Terminal::format_branch(branch_name)} not found #{App::Terminal::format_action('remotely')} in #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))}", App::Terminal::MSG_WARNING) if verbose
|
659
662
|
repo_data[:"#{BRANCH_EXISTS}"] = false
|
660
663
|
data << repo_data
|
661
664
|
next
|
@@ -736,11 +739,58 @@ module Brightpearl
|
|
736
739
|
# @return Array
|
737
740
|
def repo_loop
|
738
741
|
Array[
|
739
|
-
|
740
|
-
|
742
|
+
App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE),
|
743
|
+
App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)
|
741
744
|
]
|
742
745
|
end
|
743
746
|
|
747
|
+
# Returns short-hand string for repo.
|
748
|
+
# @return String
|
749
|
+
def get_repo_shorthand(repo_dir)
|
750
|
+
repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE) ? 'brightpearl-code' : 'brightpearl-db'
|
751
|
+
end
|
752
|
+
|
753
|
+
# Checks that a branch DOESN'T exist anywhere (local, remote, code and db). If it does, will exit with error.
|
754
|
+
# @return void
|
755
|
+
def check_branch_does_not_exist_anywhere(branch_name)
|
756
|
+
App::Terminal::info("Checking that branch #{App::Terminal::format_branch(branch_name)} doesn't already exist somewhere")
|
757
|
+
if branch_exists_anywhere(branch_name)
|
758
|
+
App::Terminal::error('Branch already exists', "Cannot continue because a branch named #{App::Terminal::format_branch(branch_name)}\x1B[38;5;240m already exists somewhere.", true)
|
759
|
+
end
|
760
|
+
end
|
761
|
+
|
762
|
+
# Checks that a branch DOES exist somewhere (local, remote, code or db). If it does not, will exit with error.
|
763
|
+
# @return void
|
764
|
+
def check_branch_exists_somewhere(branch_name)
|
765
|
+
unless branch_exists_anywhere(branch_name)
|
766
|
+
App::Terminal::error("Branch doesn't exist", "Cannot continue because branch #{App::Terminal::format_branch(branch_name)}\x1B[38;5;240m doesn't exist.", true)
|
767
|
+
end
|
768
|
+
end
|
769
|
+
|
770
|
+
# Asks if you would like to setup remote tracking. WILL ASSUME that branch doesn't have this (but won't actually check).
|
771
|
+
# @return void
|
772
|
+
def ask_to_setup_remote_tracking(current_branch, repo_dir)
|
773
|
+
tracking_setup_command = "git branch --set-upstream-to=origin/#{current_branch} #{current_branch}"
|
774
|
+
if App::Terminal::prompt_yes_no('Setup remote tracking?', ["No tracking information found for #{App::Terminal::format_branch(current_branch)} on #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))}", "By continuing, the script will automatically setup your tracking information with: #{tracking_setup_command}"])
|
775
|
+
App::Terminal::output("Setting tracking information for this branch to origin/#{current_branch}")
|
776
|
+
if !branch_exists(current_branch, repo_dir, App::Git::REMOTE)
|
777
|
+
App::Terminal::command("git push -u origin #{current_branch}", repo_dir)
|
778
|
+
end
|
779
|
+
App::Terminal::command(tracking_setup_command, repo_dir)
|
780
|
+
else
|
781
|
+
App::Terminal::warning('No remote tracking setup', "You have not setup remote tracking for branch #{App::Terminal::format_branch(current_branch)}", false)
|
782
|
+
end
|
783
|
+
end
|
784
|
+
|
785
|
+
# Get list of files that have changed between 2 branches
|
786
|
+
# @return Array
|
787
|
+
def get_changed_files(repo_dir, branch_to_compare_to = "origin/#{App::Git::MASTER}")
|
788
|
+
validate_repo_dir(repo_dir)
|
789
|
+
command = "git diff #{branch_to_compare_to}..#{current_branch_for_repo(repo_dir)} --name-only"
|
790
|
+
App::Terminal::command_capture(command, repo_dir)
|
791
|
+
end
|
792
|
+
|
793
|
+
|
744
794
|
# Validates that a parameter is either 'local' or 'remote'
|
745
795
|
# @return void
|
746
796
|
def validate_local_remote(local_remote)
|
@@ -761,8 +811,8 @@ module Brightpearl
|
|
761
811
|
# @return void
|
762
812
|
def validate_repo_dir(repo_dir)
|
763
813
|
unless Array[
|
764
|
-
|
765
|
-
|
814
|
+
App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE),
|
815
|
+
App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)
|
766
816
|
].include?(repo_dir)
|
767
817
|
abort("'#{repo_dir}' is not a valid directory.")
|
768
818
|
end
|
@@ -776,41 +826,6 @@ module Brightpearl
|
|
776
826
|
end
|
777
827
|
end
|
778
828
|
|
779
|
-
# Returns short-hand string for repo.
|
780
|
-
# @return String
|
781
|
-
def get_repo_shorthand(repo_dir)
|
782
|
-
repo_dir == Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE) ? 'brightpearl-code' : 'brightpearl-db'
|
783
|
-
end
|
784
|
-
|
785
|
-
# Checks that a branch DOESN'T exist anywhere (local, remote, code and db). If it does, will exit with error.
|
786
|
-
# @return void
|
787
|
-
def check_branch_does_not_exist_anywhere(branch_name)
|
788
|
-
Brightpearl::Terminal::info("Checking that branch #{Brightpearl::Terminal::format_branch(branch_name)} doesn't already exist somewhere")
|
789
|
-
if branch_exists_anywhere(branch_name)
|
790
|
-
Brightpearl::Terminal::error('Branch already exists', "Cannot continue because a branch named #{Brightpearl::Terminal::format_branch(branch_name)}\x1B[38;5;240m already exists somewhere.", true)
|
791
|
-
end
|
792
|
-
end
|
793
|
-
|
794
|
-
# Checks that a branch DOES exist somewhere (local, remote, code or db). If it does not, will exit with error.
|
795
|
-
# @return void
|
796
|
-
def check_branch_exists_somewhere(branch_name)
|
797
|
-
unless branch_exists_anywhere(branch_name)
|
798
|
-
Brightpearl::Terminal::error("Branch doesn't exist", "Cannot continue because branch #{Brightpearl::Terminal::format_branch(branch_name)}\x1B[38;5;240m doesn't exist.", true)
|
799
|
-
end
|
800
|
-
end
|
801
|
-
|
802
|
-
# Asks if you would like to setup remote tracking. WILL ASSUME that branch doesn't have this (but won't actually check).
|
803
|
-
# @return void
|
804
|
-
def ask_to_setup_remote_tracking(current_branch, repo_dir)
|
805
|
-
tracking_setup_command = "git branch --set-upstream-to=origin/#{current_branch} #{current_branch}"
|
806
|
-
if Brightpearl::Terminal::prompt_yes_no('Setup remote tracking?', ["No tracking information found for #{Brightpearl::Terminal::format_branch(current_branch)} on #{Brightpearl::Terminal::format_directory(get_repo_shorthand(repo_dir))}", "By continuing, the script will automatically setup your tracking information with: #{tracking_setup_command}"], Brightpearl::Terminal::MSG_WARNING)
|
807
|
-
Brightpearl::Terminal::output("Setting tracking information for this branch to origin/#{current_branch}")
|
808
|
-
Brightpearl::Terminal::command(tracking_setup_command, repo_dir)
|
809
|
-
else
|
810
|
-
Brightpearl::Terminal::warning('No remote tracking setup', "You have not setup remote tracking for branch #{Brightpearl::Terminal::format_branch(current_branch)}", false)
|
811
|
-
end
|
812
|
-
end
|
813
|
-
|
814
829
|
end
|
815
830
|
|
816
831
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module App
|
2
|
+
|
3
|
+
class GitDelete
|
4
|
+
|
5
|
+
def self.delete_local(branch_name, confirm = true, git = nil)
|
6
|
+
|
7
|
+
@git = git.nil? ? App::Git.new : git
|
8
|
+
|
9
|
+
App::Terminal::output("Must check that branch is up-to-date with it's remote counter-part, otherwise DO NOT delete!", App::Terminal::MSG_TODO)
|
10
|
+
App::Terminal::output('Must check branch even exists.', App::Terminal::MSG_TODO)
|
11
|
+
|
12
|
+
if confirm
|
13
|
+
unless App::Terminal::prompt_yes_no("#{App::Terminal::format_action('locally delete')} branch #{App::Terminal::format_branch(branch_name)}?")
|
14
|
+
App::Terminal::abort
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
@git.repo_loop.each do |repo_dir|
|
19
|
+
commands = []
|
20
|
+
if @git.current_branch_for_repo(repo_dir) == branch_name
|
21
|
+
commands << 'git checkout master'
|
22
|
+
end
|
23
|
+
commands << "git branch -d #{branch_name}"
|
24
|
+
App::Terminal::command_capture(commands, repo_dir)
|
25
|
+
end
|
26
|
+
|
27
|
+
App::Terminal::success('Branch deleted', "Successfully #{App::Terminal::format_highlight('locally')} #{App::Terminal::format_action('deleted')} branch #{App::Terminal::format_branch(branch_name)}")
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.delete_remote(branch_name, confirm = true, git = nil)
|
32
|
+
|
33
|
+
@git = git.nil? ? App::Git.new : git
|
34
|
+
|
35
|
+
App::Terminal::output('Must check branch even exists.', App::Terminal::MSG_TODO)
|
36
|
+
|
37
|
+
if confirm
|
38
|
+
unless App::Terminal::prompt_yes_no("#{App::Terminal::format_action('remotely delete')} branch #{App::Terminal::format_branch(branch_name)}?")
|
39
|
+
App::Terminal::abort
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
@git.repo_loop.each do |repo_dir|
|
44
|
+
unless @git.branch_exists(branch_name, repo_dir, App::Git::REMOTE)
|
45
|
+
puts "Branch \x1B[32m[#{branch_name}]\x1B[0m not found in: \x1B[33m#{repo_dir}\x1B[0m. Aborting \x1B[35mREMOTE DELETE\x1B[0m for this repo."
|
46
|
+
next
|
47
|
+
end
|
48
|
+
commands = [
|
49
|
+
"git branch --unset-upstream #{branch_name}",
|
50
|
+
"git push origin --delete #{branch_name}",
|
51
|
+
]
|
52
|
+
App::Terminal::command_capture(commands, repo_dir)
|
53
|
+
end
|
54
|
+
|
55
|
+
App::Terminal::success('Branch deleted', "Successfully #{App::Terminal::format_highlight('remotely')} #{App::Terminal::format_action('deleted')} branch #{App::Terminal::format_branch(branch_name)}")
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.delete_both(branch_name, confirm = true, git = nil)
|
60
|
+
|
61
|
+
@git = git.nil? ? App::Git.new : git
|
62
|
+
|
63
|
+
App::Terminal::output("Must check that branch is up-to-date with it's remote counter-part, otherwise DO NOT delete!", App::Terminal::MSG_TODO)
|
64
|
+
App::Terminal::output('Must check branch even exists.', App::Terminal::MSG_TODO)
|
65
|
+
|
66
|
+
if confirm
|
67
|
+
unless App::Terminal::prompt_yes_no("#{App::Terminal::format_action('locally & remotely delete')} branch #{App::Terminal::format_branch(branch_name)}?")
|
68
|
+
App::Terminal::abort
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
@git.repo_loop.each do |repo_dir|
|
73
|
+
commands = []
|
74
|
+
if @git.current_branch_for_repo(repo_dir) == branch_name
|
75
|
+
commands << 'git checkout master'
|
76
|
+
end
|
77
|
+
commands << "git branch -d #{branch_name}"
|
78
|
+
commands << "git branch --unset-upstream #{branch_name}"
|
79
|
+
commands << "git push origin --delete #{branch_name}"
|
80
|
+
App::Terminal::command_capture(commands, repo_dir)
|
81
|
+
end
|
82
|
+
|
83
|
+
App::Terminal::success('Branch deleted', "Successfully #{App::Terminal::format_highlight('locally')} and #{App::Terminal::format_highlight('remotely')} #{App::Terminal::format_action('deleted')} branch #{App::Terminal::format_branch(branch_name)}")
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/lib/core/jira.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module App
|
2
2
|
|
3
3
|
class Jira
|
4
4
|
|
@@ -19,7 +19,7 @@ module Brightpearl
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
if jira_number.nil?
|
22
|
-
|
22
|
+
App::Terminal::error('Invalid Jira Number', "The Jira Number must be a 4-5 digit number. You tried to pass: #{App::Terminal::format_invalid(argument)}", true)
|
23
23
|
end
|
24
24
|
jira_number
|
25
25
|
end
|