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/routes/git_push.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppCommand
|
2
2
|
|
3
3
|
class GitPush < ::Convoy::ActionCommand::Base
|
4
4
|
|
@@ -6,7 +6,7 @@ module BrightpearlCommand
|
|
6
6
|
|
7
7
|
@opts = command_options
|
8
8
|
@args = arguments
|
9
|
-
@git =
|
9
|
+
@git = App::Git.new
|
10
10
|
|
11
11
|
opts_validate
|
12
12
|
opts_routing
|
@@ -16,7 +16,7 @@ module BrightpearlCommand
|
|
16
16
|
def opts_validate
|
17
17
|
|
18
18
|
if @args[0].nil?
|
19
|
-
@args[0] = @git.current_branch_for_repo(
|
19
|
+
@args[0] = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
@@ -29,17 +29,26 @@ module BrightpearlCommand
|
|
29
29
|
|
30
30
|
def git_push
|
31
31
|
|
32
|
-
@git.check_for_same_branch(
|
33
|
-
branch_code = @git.current_branch_for_repo(
|
34
|
-
branch_db = @git.current_branch_for_repo(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
@git.check_for_same_branch(App::Git::SAME_BRANCH_WARNING)
|
33
|
+
branch_code = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
34
|
+
branch_db = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))
|
35
|
+
|
36
|
+
branches_to_push = []
|
37
|
+
branches_to_push << "#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))} will push #{App::Terminal::format_branch(branch_code)} \xe2\x86\x92 #{App::Terminal::format_branch("origin/#{branch_code}")}" unless branch_code == App::Git::MASTER
|
38
|
+
branches_to_push << "#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))} will push #{App::Terminal::format_branch(branch_db)} \xe2\x86\x92 #{App::Terminal::format_branch("origin/#{branch_db}")}" unless branch_db == App::Git::MASTER
|
39
|
+
|
40
|
+
unless branches_to_push.any?
|
41
|
+
App::Terminal::error("#{App::Terminal::format_action('pushing')} to #{App::Terminal::format_branch(App::Git::MASTER)} is best done manually.", nil, true)
|
42
|
+
end
|
43
|
+
|
44
|
+
if App::Terminal::prompt_yes_no("#{App::Terminal::format_action('push')} the following repos:", branches_to_push)
|
39
45
|
@git.check_for_uncommitted_files(true)
|
40
46
|
@git.repo_loop.each do |repo_dir|
|
41
|
-
|
42
|
-
|
47
|
+
current_branch = @git.current_branch_for_repo(repo_dir)
|
48
|
+
if current_branch != App::Git::MASTER
|
49
|
+
unless App::Terminal::command_capture("git push origin #{current_branch}", repo_dir)
|
50
|
+
App::Terminal::warning('Something went wrong', "Not sure what the reason was, but doing a #{App::Terminal::format_command('git push')} on #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} was unsuccessful.")
|
51
|
+
end
|
43
52
|
end
|
44
53
|
end
|
45
54
|
@git.check_for_stash(true)
|
data/lib/routes/git_stash.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppCommand
|
2
2
|
|
3
3
|
class GitStash < ::Convoy::ActionCommand::Base
|
4
4
|
|
@@ -6,7 +6,7 @@ module BrightpearlCommand
|
|
6
6
|
|
7
7
|
@opts = command_options
|
8
8
|
@args = arguments
|
9
|
-
@git =
|
9
|
+
@git = App::Git.new
|
10
10
|
opts_validate
|
11
11
|
opts_routing
|
12
12
|
|
@@ -24,16 +24,21 @@ module BrightpearlCommand
|
|
24
24
|
|
25
25
|
def show_all_stashes
|
26
26
|
|
27
|
+
no_stash_found_count = 0
|
27
28
|
@git.repo_loop.each do |repo_dir|
|
28
29
|
stashes = `cd #{repo_dir} && git stash list`
|
29
30
|
stashes = stashes.split("\n")
|
30
31
|
# Skip if no stashes.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
if stashes.any?
|
33
|
+
App::Terminal::info("Showing stashes for: #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))}")
|
34
|
+
stashes.each do |stash|
|
35
|
+
stash_name = stash.split(/:/).first
|
36
|
+
output = App::Terminal::command_capture("git stash show --name-only #{stash_name}", repo_dir, false)
|
37
|
+
App::Terminal::info("#{stash}", output[0], false)
|
38
|
+
end
|
39
|
+
else
|
40
|
+
App::Terminal::info("No stashes found in: #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))}", nil, (no_stash_found_count > 0) ? false : true)
|
41
|
+
no_stash_found_count = no_stash_found_count + 1
|
37
42
|
end
|
38
43
|
end
|
39
44
|
|
data/lib/routes/git_update.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
module
|
1
|
+
module AppCommand
|
2
2
|
|
3
3
|
class GitUpdate < ::Convoy::ActionCommand::Base
|
4
4
|
|
5
5
|
def execute
|
6
|
-
@git =
|
6
|
+
@git = App::Git.new
|
7
7
|
@opts = command_options
|
8
8
|
opts_validate
|
9
9
|
opts_routing
|
@@ -14,14 +14,7 @@ module BrightpearlCommand
|
|
14
14
|
|
15
15
|
def opts_routing
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
Brightpearl::Terminal::error('Note yet implemented', "Must write code to update ALL branches.\nCould get complicated as there will likely be merge conflicts.\nMust think about this...", true)
|
20
|
-
|
21
|
-
# update_branch_all
|
22
|
-
else
|
23
|
-
update_branch_single
|
24
|
-
end
|
17
|
+
update_branch_single
|
25
18
|
|
26
19
|
end
|
27
20
|
|
@@ -32,28 +25,30 @@ module BrightpearlCommand
|
|
32
25
|
@git.repo_loop.each do |repo_dir|
|
33
26
|
current_branch = @git.current_branch_for_repo(repo_dir)
|
34
27
|
commands = Array.new
|
35
|
-
if current_branch !=
|
36
|
-
commands <<
|
28
|
+
if current_branch != App::Git::MASTER
|
29
|
+
commands << "git checkout #{App::Git::MASTER}"
|
37
30
|
end
|
38
|
-
commands <<
|
39
|
-
if current_branch !=
|
31
|
+
commands << "git pull origin #{App::Git::MASTER}"
|
32
|
+
if current_branch != App::Git::MASTER
|
40
33
|
commands << "git checkout #{current_branch}"
|
41
|
-
commands <<
|
34
|
+
commands << "git pull origin #{current_branch}"
|
42
35
|
commands << 'git merge master'
|
43
36
|
end
|
44
|
-
results =
|
45
|
-
if current_branch !=
|
37
|
+
results = App::Terminal::command(commands, repo_dir)
|
38
|
+
if current_branch != App::Git::MASTER
|
46
39
|
if results[3] == false
|
47
40
|
@git.ask_to_setup_remote_tracking(current_branch, repo_dir)
|
48
41
|
end
|
49
42
|
if results[4] == false
|
50
|
-
|
43
|
+
unless App::Terminal::prompt_yes_no('Merge conflict occurred', ["Unable to successfully merge #{App::Terminal::format_branch(App::Git::MASTER)} into #{App::Terminal::format_branch(current_branch)} on #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))}", "Please #{App::Terminal::format_action('open an IDE')}\x1B[38;5;240m and resolve your conflicts as soon as this script has finished executing."])
|
44
|
+
App::Terminal::abort(nil, nil, true, false)
|
45
|
+
end
|
51
46
|
end
|
52
47
|
end
|
53
|
-
if @opts[:push] && current_branch !=
|
54
|
-
|
55
|
-
elsif @opts[:push] && current_branch ==
|
56
|
-
|
48
|
+
if @opts[:push] && current_branch != App::Git::MASTER
|
49
|
+
App::Terminal::command("git push origin #{current_branch}", repo_dir)
|
50
|
+
elsif @opts[:push] && current_branch == App::Git::MASTER
|
51
|
+
App::Terminal::warning("#{App::Terminal::format_action('push')} to #{App::Terminal::format_branch(App::Git::MASTER)} not allowed!", ["Your #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} repo is currently on #{App::Terminal::format_branch(App::Git::MASTER)}", "The script will not perform a #{App::Terminal::format_action('push')} as requested for safety reasons."])
|
57
52
|
end
|
58
53
|
|
59
54
|
end
|
data/lib/routes/jira.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppCommand
|
2
2
|
|
3
3
|
class JiraCard < ::Convoy::ActionCommand::Base
|
4
4
|
|
@@ -6,7 +6,7 @@ module BrightpearlCommand
|
|
6
6
|
|
7
7
|
@opts = command_options
|
8
8
|
@args = arguments
|
9
|
-
@jira =
|
9
|
+
@jira = App::Jira.new
|
10
10
|
|
11
11
|
opts_validate
|
12
12
|
opts_routing
|
@@ -26,7 +26,7 @@ module BrightpearlCommand
|
|
26
26
|
|
27
27
|
if @opts[:card]
|
28
28
|
if @args[0].nil? || @args[0] == ''
|
29
|
-
|
29
|
+
App::Terminal::error('Argument required', 'You must supply a valid Jira Number as an argument.', true)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'columnist'
|
2
2
|
require 'rest-client'
|
3
3
|
|
4
|
-
module
|
4
|
+
module AppCommand
|
5
5
|
|
6
6
|
class ProductionLogs < ::Convoy::ActionCommand::Base
|
7
7
|
|
@@ -21,8 +21,8 @@ module BrightpearlCommand
|
|
21
21
|
@opts = command_options
|
22
22
|
@args = arguments
|
23
23
|
|
24
|
-
@ec2_connection =
|
25
|
-
@terminal_width =
|
24
|
+
@ec2_connection = App::MySQL::ec2
|
25
|
+
@terminal_width = App::Terminal::get_terminal_width
|
26
26
|
|
27
27
|
opts_validate
|
28
28
|
opts_routing
|
@@ -36,7 +36,7 @@ module BrightpearlCommand
|
|
36
36
|
watch = watch + 1 if @opts[:watchJava]
|
37
37
|
|
38
38
|
if watch >= 2
|
39
|
-
|
39
|
+
App::Terminal::error('You can only watch one set of logs at a time', "Please set only 1 one of the following flags: #{App::Terminal::format_flag('p', false)} #{App::Terminal::format_flag('j', false)}", true)
|
40
40
|
elsif watch == 0
|
41
41
|
@opts[:watchPHP] = true
|
42
42
|
end
|
@@ -44,7 +44,7 @@ module BrightpearlCommand
|
|
44
44
|
if @opts[:compare]
|
45
45
|
[@args[0], @args[1]].each do |version_number|
|
46
46
|
if version_number.nil?
|
47
|
-
|
47
|
+
App::Terminal::error('Missing arguments', ["When using the #{App::Terminal::format_flag('c')} the system expects #{App::Terminal::format_highlight('2 arguments ')} \xe2\x80\x94 application version numbers.", "An example of a valid command would be: #{App::Terminal::format_command('bp p l -c 4.76.6 4.78.4')}"], true)
|
48
48
|
end
|
49
49
|
validate_version_number(version_number)
|
50
50
|
end
|
@@ -131,14 +131,14 @@ module BrightpearlCommand
|
|
131
131
|
puts # PUTS SPACE AFTER TABLE
|
132
132
|
|
133
133
|
rescue Exception => e
|
134
|
-
|
134
|
+
App::Terminal::error('Something went wrong', "#{e.message}", true)
|
135
135
|
end
|
136
136
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def watch_java
|
140
140
|
|
141
|
-
|
141
|
+
App::Terminal::info('Not yet implemented', 'Please wait for Albert to program this and try again later.')
|
142
142
|
exit
|
143
143
|
|
144
144
|
end
|
@@ -184,7 +184,7 @@ module BrightpearlCommand
|
|
184
184
|
error_output << log_message
|
185
185
|
error_output << nil
|
186
186
|
error_output << sql
|
187
|
-
|
187
|
+
App::Terminal::warning('Query Failed', error_output)
|
188
188
|
end
|
189
189
|
end
|
190
190
|
error_parsed = " \x1B[38;5;34m#{account_version}\x1B[0m \xe2\x86\x92 \x1B[38;5;81m#{account_name}\x1B[0m \xe2\x80\x94 \x1B[38;5;#{error_color}m#{error_message} \xe2\x80\x94 #{error_file} \xe2\x80\x94 Line #{error_line}"
|
@@ -211,7 +211,7 @@ module BrightpearlCommand
|
|
211
211
|
LOG_URI_STG2,
|
212
212
|
]
|
213
213
|
raw_log_uris.each do |log_uri|
|
214
|
-
|
214
|
+
App::Terminal::output("Retrieving data from: #{log_uri}")
|
215
215
|
raw_log_data << RestClient.get(log_uri)
|
216
216
|
end
|
217
217
|
|
@@ -314,16 +314,16 @@ module BrightpearlCommand
|
|
314
314
|
# @return void
|
315
315
|
def validate_version_number(version_number)
|
316
316
|
unless version_number =~ /\A\d\.\d{1,3}\.\d{1,2}\z/
|
317
|
-
|
317
|
+
App::Terminal::error('Invalid version number', "#{App::Terminal::format_highlight(version_number)} is not a valid version number.", true)
|
318
318
|
end
|
319
319
|
sql = "SELECT id FROM php_logs WHERE account_version='#{version_number}' LIMIT 1"
|
320
320
|
begin
|
321
321
|
result = @ec2_connection.query(sql)
|
322
322
|
rescue
|
323
|
-
|
323
|
+
App::Terminal::warning('Query Failed', sql)
|
324
324
|
end
|
325
325
|
unless result.num_rows > 0
|
326
|
-
|
326
|
+
App::Terminal::info('No data', "We currently don't have any data for version: #{App::Terminal::format_highlight(version_number)}")
|
327
327
|
exit
|
328
328
|
end
|
329
329
|
end
|
data/lib/routes/reset.rb
CHANGED
data/lib/routes/review.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppCommand
|
2
2
|
|
3
3
|
class Review < ::Convoy::ActionCommand::Base
|
4
4
|
|
@@ -6,7 +6,7 @@ module BrightpearlCommand
|
|
6
6
|
|
7
7
|
@opts = command_options
|
8
8
|
@args = arguments
|
9
|
-
@git =
|
9
|
+
@git = App::Git.new
|
10
10
|
opts_validate
|
11
11
|
opts_routing
|
12
12
|
|
@@ -15,8 +15,9 @@ module BrightpearlCommand
|
|
15
15
|
def opts_validate
|
16
16
|
|
17
17
|
unless @args.any?
|
18
|
-
|
19
|
-
|
18
|
+
|
19
|
+
App::Terminal::error('Must specify a valid branch name', nil, true)
|
20
|
+
|
20
21
|
end
|
21
22
|
|
22
23
|
end
|
@@ -29,7 +30,7 @@ module BrightpearlCommand
|
|
29
30
|
|
30
31
|
def review
|
31
32
|
|
32
|
-
current_branch = @git.current_branch_for_repo(
|
33
|
+
current_branch = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
33
34
|
|
34
35
|
@git.check_branch_exists_somewhere(@args[0])
|
35
36
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppCommand
|
2
2
|
|
3
3
|
class ScriptsApiDocs < ::Convoy::ActionCommand::Base
|
4
4
|
|
@@ -23,14 +23,14 @@ module BrightpearlCommand
|
|
23
23
|
|
24
24
|
def build_api_docs
|
25
25
|
|
26
|
-
if
|
26
|
+
if App::Tools::this_is_a_mac
|
27
27
|
|
28
|
-
|
29
|
-
system("sshpass -p#{
|
28
|
+
App::Terminal::info('Building API Docs')
|
29
|
+
system("sshpass -p#{App::Config.param(App::Config::VM_USER_PASSWORD)} ssh #{App::Config.param(App::Config::VM_USER)}@#{App::Config.param(App::Config::VM_IP)} -t 'su root && cd /brightpearl-source/dev-vm-control-scripts && ./build-api-docs'")
|
30
30
|
|
31
31
|
else
|
32
32
|
|
33
|
-
|
33
|
+
App::Terminal::info('This functionality has not yet been implemented on your OS', ["Currently only works on #{App::Terminal::format_action(App::Config.param(App::Config::WORKSTATION_OS))}", nil, "You are on #{App::Terminal::format_action(App::Config.param(App::Config::WORKSTATION_OS))}"])
|
34
34
|
|
35
35
|
end
|
36
36
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppCommand
|
2
2
|
|
3
3
|
class ScriptsBranchCleaner < ::Convoy::ActionCommand::Base
|
4
4
|
|
@@ -6,7 +6,7 @@ module BrightpearlCommand
|
|
6
6
|
|
7
7
|
@opts = command_options
|
8
8
|
@args = arguments
|
9
|
-
@git =
|
9
|
+
@git = App::Git.new
|
10
10
|
|
11
11
|
opts_validate
|
12
12
|
opts_routing
|
@@ -15,14 +15,6 @@ module BrightpearlCommand
|
|
15
15
|
|
16
16
|
def opts_validate
|
17
17
|
|
18
|
-
if @opts[:scanLocal] && @opts[:scanRemote]
|
19
|
-
Brightpearl::Terminal::error("Cannot scan #{Brightpearl::Terminal::format_action('local')} & #{Brightpearl::Terminal::format_action('remote')} simultaneously", "Must use either the #{Brightpearl::Terminal::format_flag('l')} or the #{Brightpearl::Terminal::format_flag('r')} \xe2\x80\x94 cannot use both.", true)
|
20
|
-
end
|
21
|
-
|
22
|
-
if @opts[:scanLocal] == false && @opts[:scanRemote] == false
|
23
|
-
@opts[:scanLocal] = true
|
24
|
-
end
|
25
|
-
|
26
18
|
end
|
27
19
|
|
28
20
|
def opts_routing
|
@@ -33,12 +25,10 @@ module BrightpearlCommand
|
|
33
25
|
|
34
26
|
def clean
|
35
27
|
|
36
|
-
|
37
|
-
|
38
|
-
Brightpearl::Terminal::info('Running branch cleaner', "Gathering list of #{Brightpearl::Terminal::format_action(local_remote)} branches which are safe to delete.")
|
28
|
+
App::Terminal::info('Running branch cleaner', "Gathering list of #{App::Terminal::format_highlight('local')} branches where last commit was #{App::Terminal::format_highlight('more than 1 month ago')}")
|
39
29
|
|
40
30
|
branches_code, branches_db = get_historic_branches
|
41
|
-
umc_branches =
|
31
|
+
umc_branches = get_unmerged_commit_branches(branches_code, branches_db)
|
42
32
|
fnl_branches_cd, fnl_branches_db = get_final_branches(branches_code, branches_db, umc_branches)
|
43
33
|
|
44
34
|
puts "\n"
|
@@ -46,99 +36,90 @@ module BrightpearlCommand
|
|
46
36
|
atleast_one_error = false
|
47
37
|
|
48
38
|
if umc_branches.any?
|
49
|
-
|
39
|
+
App::Terminal::warning("The following branches have commits which #{App::Terminal::format_invalid('have not been merged to', true)} #{App::Terminal::format_branch(App::Git::MASTER)}", umc_branches, false)
|
50
40
|
atleast_one_error = true
|
51
41
|
end
|
52
42
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
43
|
+
unless fnl_branches_cd.any? || fnl_branches_db.any?
|
44
|
+
App::Terminal::info('No branches to delete', ["The script found no branches which are #{App::Terminal::format_action('eligible for deletion')}.","All branches on your system have either a #{App::Terminal::format_highlight('commit within the last month')} or a #{App::Terminal::format_highlight('commit not in')} #{App::Terminal::format_branch(App::Git::MASTER)}."])
|
45
|
+
exit
|
57
46
|
end
|
58
47
|
|
59
|
-
|
60
|
-
|
61
|
-
|
48
|
+
if atleast_one_error
|
49
|
+
unless App::Terminal::prompt_yes_no('Skip these branches?', ["The above branch(es) have unmerged commits and will be #{App::Terminal::format_action('skipped')} in the removal process.", "You #{App::Terminal::format_invalid('cannot delete', true)} these branches using this script, this must be done manually #{App::Terminal::format_highlight('afterwards')}."])
|
50
|
+
App::Terminal::abort(nil, nil, true, false)
|
51
|
+
end
|
62
52
|
end
|
63
53
|
|
64
54
|
@git.show_branches_draw_table(fnl_branches_cd, fnl_branches_db)
|
65
55
|
|
66
|
-
unless
|
67
|
-
|
56
|
+
unless App::Terminal::prompt_yes_no('Remove these branches?', ["By continuing, the above branches will be #{App::Terminal::format_action('removed permanently')} both #{App::Terminal::format_highlight('locally & remotely')}!"], 'Are you absolutely sure you want to continue?', false)
|
57
|
+
App::Terminal::abort(nil, nil, true, false)
|
68
58
|
end
|
69
59
|
|
70
|
-
repo_cd =
|
71
|
-
repo_db =
|
60
|
+
repo_cd = App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)
|
61
|
+
repo_db = App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)
|
72
62
|
|
73
63
|
branch_count = 0
|
74
64
|
|
75
65
|
fnl_branches_cd.each do |branch|
|
76
|
-
branch_name = branch[:"#{
|
77
|
-
|
78
|
-
|
79
|
-
commands << "git branch -D #{branch_name}"
|
80
|
-
else
|
66
|
+
branch_name = branch[:"#{App::Git::REFNAME}"]
|
67
|
+
unless branch_name == App::Git::MASTER
|
68
|
+
commands = []
|
81
69
|
commands << "git branch --unset-upstream #{branch_name}"
|
82
|
-
commands << "git
|
70
|
+
commands << "git branch -D #{branch_name}"
|
71
|
+
commands << "git push origin --delete #{branch_name}" unless release_branch(branch_name)
|
72
|
+
App::Terminal::command(commands, repo_cd)
|
73
|
+
branch_count = branch_count + 1
|
83
74
|
end
|
84
|
-
Brightpearl::Terminal::command(commands, repo_cd)
|
85
|
-
branch_count = branch_count + 1
|
86
75
|
end
|
87
76
|
|
88
77
|
fnl_branches_db.each do |branch|
|
89
|
-
branch_name = branch[:"#{
|
90
|
-
|
91
|
-
|
92
|
-
commands << "git branch -D #{branch_name}"
|
93
|
-
else
|
78
|
+
branch_name = branch[:"#{App::Git::REFNAME}"]
|
79
|
+
unless branch_name == App::Git::MASTER
|
80
|
+
commands = []
|
94
81
|
commands << "git branch --unset-upstream #{branch_name}"
|
95
|
-
commands << "git
|
82
|
+
commands << "git branch -D #{branch_name}"
|
83
|
+
commands << "git push origin --delete #{branch_name}" unless release_branch(branch_name)
|
84
|
+
App::Terminal::command(commands, repo_db)
|
85
|
+
branch_count = branch_count + 1
|
96
86
|
end
|
97
|
-
Brightpearl::Terminal::command(commands, repo_db)
|
98
|
-
branch_count = branch_count + 1
|
99
87
|
end
|
100
88
|
|
101
|
-
|
102
|
-
|
89
|
+
App::Terminal::success("#{App::Terminal::format_highlight(branch_count)} branches successfully #{App::Terminal::format_action('removed')}")
|
103
90
|
end
|
104
91
|
|
105
92
|
private
|
106
93
|
|
94
|
+
def release_branch(branch)
|
95
|
+
branch =~ /release-(\d){1,3}.(\d){1,3}.(\d){1,3}-(\d){4}/i
|
96
|
+
end
|
97
|
+
|
107
98
|
# Gets all (remote) branches where last commit was longer than 1 month ago and committer is CONFIG::GIT_USERNAME
|
108
99
|
# @return Array
|
109
100
|
def get_historic_branches
|
110
101
|
|
111
|
-
committer_name = Brightpearl::Config.param(Brightpearl::Config::GIT_USERNAME)
|
112
102
|
date_1_month_ago = DateTime.now << 1
|
113
103
|
|
114
104
|
fnl_branches_cd = []
|
115
105
|
fnl_branches_db = []
|
106
|
+
all_branches_db = []
|
116
107
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
repos[0].each do |branch|
|
124
|
-
unless branch[:"#{Brightpearl::Git::REFNAME}"].match(Brightpearl::Git::RELEASE_BRANCH_REGEX) || branch[:"#{Brightpearl::Git::COMMITTER_DATE}"] > date_1_month_ago
|
125
|
-
if branch[:"#{Brightpearl::Git::COMMITTER_NAME}"] == committer_name && @opts[:anyName] == false
|
126
|
-
fnl_branches_cd << branch
|
127
|
-
elsif @opts[:anyName] == true
|
128
|
-
fnl_branches_cd << branch
|
129
|
-
end
|
108
|
+
repos = @git.get_local_branches(App::Git::SORT_DATE)
|
109
|
+
repos[1].each do |branch|
|
110
|
+
all_branches_db << branch[:"#{App::Git::REFNAME}"]
|
111
|
+
if branch[:"#{App::Git::COMMITTER_DATE}"] < date_1_month_ago
|
112
|
+
fnl_branches_db << branch
|
130
113
|
end
|
131
114
|
end
|
132
|
-
repos[
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
elsif @opts[:anyName] == true
|
115
|
+
repos[0].each do |branch|
|
116
|
+
if branch[:"#{App::Git::COMMITTER_DATE}"] < date_1_month_ago
|
117
|
+
fnl_branches_cd << branch
|
118
|
+
if all_branches_db.include?(branch[:"#{App::Git::REFNAME}"])
|
137
119
|
fnl_branches_db << branch
|
138
120
|
end
|
139
121
|
end
|
140
122
|
end
|
141
|
-
|
142
123
|
fnl_branches_cd.uniq!
|
143
124
|
fnl_branches_db.uniq!
|
144
125
|
return fnl_branches_cd, fnl_branches_db
|
@@ -146,21 +127,24 @@ module BrightpearlCommand
|
|
146
127
|
|
147
128
|
# Gets array of branches which still have commits NOT in master.
|
148
129
|
# @return Array
|
149
|
-
def
|
130
|
+
def get_unmerged_commit_branches(branches_code, branches_db)
|
150
131
|
branches_unmerged_commits = []
|
151
|
-
origin = @opts[:scanLocal] ? '' : 'origin/'
|
152
132
|
branches_code.each do |code_branch|
|
153
|
-
missing_commits =
|
133
|
+
missing_commits = App::Terminal::command_capture("git log origin/master..origin/#{code_branch[:"#{App::Git::REFNAME}"]}", App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE), true, false)
|
154
134
|
if missing_commits[0] != ''
|
155
|
-
|
156
|
-
|
135
|
+
missing_commits[0].split("\n").each do |line|
|
136
|
+
App::Terminal::output(line, App::Terminal::MSG_WARNING)
|
137
|
+
end
|
138
|
+
branches_unmerged_commits << code_branch[:"#{App::Git::REFNAME}"]
|
157
139
|
end
|
158
140
|
end
|
159
141
|
branches_db.each do |db_branch|
|
160
|
-
missing_commits =
|
142
|
+
missing_commits = App::Terminal::command_capture("git log origin/master..origin/#{db_branch[:"#{App::Git::REFNAME}"]}", App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB), true, false)
|
161
143
|
if missing_commits[0] != ''
|
162
|
-
|
163
|
-
|
144
|
+
missing_commits[0].split("\n").each do |line|
|
145
|
+
App::Terminal::output(line, App::Terminal::MSG_WARNING)
|
146
|
+
end
|
147
|
+
branches_unmerged_commits << db_branch[:"#{App::Git::REFNAME}"]
|
164
148
|
end
|
165
149
|
end
|
166
150
|
branches_unmerged_commits.uniq!
|
@@ -171,20 +155,15 @@ module BrightpearlCommand
|
|
171
155
|
# Gets final array of branches which are safe to delete.
|
172
156
|
# @return Array
|
173
157
|
def get_final_branches(branches_code, branches_db, umc_branches)
|
174
|
-
|
175
|
-
puts branches_code
|
176
|
-
puts umc_branches
|
177
|
-
exit
|
178
|
-
|
179
158
|
fnl_branches_cd = []
|
180
159
|
fnl_branches_db = []
|
181
160
|
branches_code.each do |branch|
|
182
|
-
unless umc_branches.include?(branch[:"#{
|
161
|
+
unless umc_branches.include?(branch[:"#{App::Git::REFNAME}"])
|
183
162
|
fnl_branches_cd << branch
|
184
163
|
end
|
185
164
|
end
|
186
165
|
branches_db.each do |branch|
|
187
|
-
unless umc_branches.include?(branch[:"#{
|
166
|
+
unless umc_branches.include?(branch[:"#{App::Git::REFNAME}"])
|
188
167
|
fnl_branches_db << branch
|
189
168
|
end
|
190
169
|
end
|
data/lib/routes/scripts_color.rb
CHANGED