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.
Files changed (46) hide show
  1. checksums.yaml +5 -13
  2. data/bin/bp +1 -1
  3. data/bin/brightpearl +1 -1
  4. data/lib/brightpearl_cli.rb +161 -168
  5. data/lib/core/api.rb +1 -1
  6. data/lib/core/config.rb +10 -133
  7. data/lib/core/config_unique.rb +113 -0
  8. data/lib/core/encrypter.rb +6 -6
  9. data/lib/core/enums.rb +1 -1
  10. data/lib/core/git.rb +123 -108
  11. data/lib/core/git_delete.rb +89 -0
  12. data/lib/core/jira.rb +2 -2
  13. data/lib/core/mysql.rb +14 -14
  14. data/lib/core/pom.rb +129 -0
  15. data/lib/core/terminal.rb +28 -8
  16. data/lib/core/tools.rb +6 -6
  17. data/lib/core/utils_files.rb +92 -0
  18. data/lib/core/utils_routes.rb +25 -0
  19. data/lib/core/utils_strings.rb +45 -0
  20. data/lib/core/validate.rb +1 -1
  21. data/lib/routes/build.rb +16 -17
  22. data/lib/routes/dummy_order.rb +5 -5
  23. data/lib/routes/fix.rb +49 -0
  24. data/lib/routes/git_branch.rb +6 -6
  25. data/lib/routes/git_checkout.rb +42 -33
  26. data/lib/routes/git_delete.rb +8 -62
  27. data/lib/routes/git_merge.rb +198 -111
  28. data/lib/routes/git_pull.rb +11 -11
  29. data/lib/routes/git_push.rb +21 -12
  30. data/lib/routes/git_stash.rb +13 -8
  31. data/lib/routes/git_update.rb +17 -22
  32. data/lib/routes/jira.rb +3 -3
  33. data/lib/routes/production_logs.rb +12 -12
  34. data/lib/routes/reset.rb +1 -1
  35. data/lib/routes/review.rb +6 -5
  36. data/lib/routes/scripts_api_docs.rb +5 -5
  37. data/lib/routes/scripts_branch_cleaner.rb +58 -79
  38. data/lib/routes/scripts_color.rb +1 -1
  39. data/lib/routes/scripts_pom_fixer.rb +5 -62
  40. data/lib/routes/scripts_sonar.rb +82 -0
  41. data/lib/routes/setup.rb +6 -6
  42. data/lib/routes/tail.rb +5 -5
  43. data/lib/routes/test.rb +3 -3
  44. data/lib/routes/update.rb +1 -1
  45. metadata +16 -9
  46. data/lib/routes/scripts_code_sniffer.rb +0 -36
data/lib/routes/fix.rb ADDED
@@ -0,0 +1,49 @@
1
+ module AppCommand
2
+
3
+ class Fix < ::Convoy::ActionCommand::Base
4
+
5
+ def execute
6
+
7
+ @opts = command_options
8
+ @args = arguments
9
+
10
+ @mysql_app = App::MySQL::vm
11
+ @mysql_ses = App::MySQL::vm('_session')
12
+
13
+ opts_validate
14
+ opts_routing
15
+
16
+ end
17
+
18
+ def opts_validate
19
+
20
+ end
21
+
22
+ def opts_routing
23
+
24
+ if @opts[:clear_sessions]
25
+ clear_sessions
26
+ else
27
+ system('bp f -h')
28
+ end
29
+
30
+ end
31
+
32
+ def clear_sessions
33
+ App::Terminal::info('Attempting to clear all sessions from DB..')
34
+
35
+ App::Terminal::output('DELETE FROM _session.session;')
36
+ @mysql_ses.query('DELETE FROM session;')
37
+
38
+ App::Terminal::output('DELETE FROM app.session_to_licence_type;')
39
+ @mysql_app.query('DELETE FROM session_to_licence_type;')
40
+
41
+ App::Terminal::output('DELETE FROM app.sessions;')
42
+ @mysql_app.query('DELETE FROM sessions;')
43
+
44
+ puts
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -1,12 +1,12 @@
1
- module BrightpearlCommand
1
+ module AppCommand
2
2
 
3
3
  class GitBranch < ::Convoy::ActionCommand::Base
4
4
 
5
5
  def execute
6
6
 
7
7
  @opts = command_options
8
- @sort = Brightpearl::Git::SORT_REFNAME
9
- @git = Brightpearl::Git.new
8
+ @sort = App::Git::SORT_REFNAME
9
+ @git = App::Git.new
10
10
  opts_validate
11
11
  opts_routing
12
12
 
@@ -18,7 +18,7 @@ module BrightpearlCommand
18
18
  # @todo Change to new style error messages.
19
19
  abort('Cannot list both local & remote branches simultaneously. Please choose one option only.')
20
20
  end
21
- @sort = Brightpearl::Git::SORT_DATE if @opts[:sortDate]
21
+ @sort = App::Git::SORT_DATE if @opts[:sortDate]
22
22
 
23
23
  end
24
24
 
@@ -41,13 +41,13 @@ module BrightpearlCommand
41
41
  # List local branches.
42
42
  # @return void
43
43
  def list_local_branches
44
- @git.show_branches(@sort, Brightpearl::Git::LOCAL)
44
+ @git.show_branches(@sort, App::Git::LOCAL)
45
45
  end
46
46
 
47
47
  # List remote branches.
48
48
  # @return void
49
49
  def list_remote_branches
50
- @git.show_branches(@sort, Brightpearl::Git::REMOTE)
50
+ @git.show_branches(@sort, App::Git::REMOTE)
51
51
  end
52
52
 
53
53
  end
@@ -1,4 +1,4 @@
1
- module BrightpearlCommand
1
+ module AppCommand
2
2
 
3
3
  class GitCheckout < ::Convoy::ActionCommand::Base
4
4
 
@@ -6,7 +6,7 @@ module BrightpearlCommand
6
6
 
7
7
  @opts = command_options
8
8
  @args = arguments
9
- @git = Brightpearl::Git.new
9
+ @git = App::Git.new
10
10
 
11
11
  opts_validate
12
12
  opts_routing
@@ -16,13 +16,15 @@ module BrightpearlCommand
16
16
  def opts_validate
17
17
 
18
18
  unless @args.any?
19
+
19
20
  if @opts[:branch] || @opts[:branch_origin]
20
- Brightpearl::Terminal::error('You must specify a branch name')
21
+ App::Terminal::error('You must specify a branch name')
21
22
  else
22
- puts "\n\x1B[41m ERROR \x1B[0m You must specify a branch to checkout. Here is a list of your \x1B[35mLOCAL BRANCHES\x1B[0m"
23
- Brightpearl::Git.new.show_branches(Brightpearl::Git::SORT_REFNAME, Brightpearl::Git::LOCAL)
23
+ system('bp g co -h')
24
24
  end
25
+
25
26
  exit
27
+
26
28
  end
27
29
 
28
30
  end
@@ -44,42 +46,48 @@ module BrightpearlCommand
44
46
  def create_branch(push_to_origin = false)
45
47
 
46
48
  new_branch_name = @args[0]
47
- source_branch_name = @args[1].nil? ? Brightpearl::Git::MASTER : @args[1]
49
+ source_branch_name = @args[1].nil? ? App::Git::MASTER : @args[1]
50
+
51
+ # If new branch is 12345, add 'bp-' prefix.
52
+ if new_branch_name =~ /\A\d{5}\z/i
53
+ new_branch_name = "bp-#{new_branch_name}"
54
+ end
48
55
 
49
56
  # Validate that new branch doesn't already exist.
50
57
  @git.check_branch_does_not_exist_anywhere(new_branch_name)
51
58
 
52
59
  # Validate that source branch (if not MASTER) exists locally.
53
- if source_branch_name != Brightpearl::Git::MASTER
60
+ if source_branch_name != App::Git::MASTER
54
61
  @git.check_branch_exists_somewhere(source_branch_name)
55
62
  end
56
63
 
57
64
  @git.check_for_uncommitted_files
58
- if Brightpearl::Terminal::prompt_yes_no('Create new branch?', "You're about to cut branch #{Brightpearl::Terminal::format_branch(new_branch_name)}\x1B[38;5;240m from #{Brightpearl::Terminal::format_branch(source_branch_name)}\x1B[38;5;240m#{push_to_origin ? ' and push it to origin.' : ''}")
65
+
66
+ if App::Terminal::prompt_yes_no('Create new branch?', "You're about to cut branch #{App::Terminal::format_branch(new_branch_name)}\x1B[38;5;240m from #{App::Terminal::format_branch(source_branch_name)}\x1B[38;5;240m#{push_to_origin ? ' and push it to origin.' : ''}")
59
67
  source_branch_final = []
60
68
  source_branch_data = @git.branch_data(source_branch_name)
61
69
  source_branch_data.each do |branch_data|
62
- if branch_data[:"#{Brightpearl::Git::BRANCH_EXISTS}"]
70
+ if branch_data[:"#{App::Git::BRANCH_EXISTS}"]
63
71
  sb = source_branch_name
64
72
  source_branch_final << source_branch_name
65
73
  else
66
- sb = Brightpearl::Git::MASTER
67
- source_branch_final << Brightpearl::Git::MASTER
68
- if source_branch_name != Brightpearl::Git::MASTER
69
- Brightpearl::Terminal::warning('Branch not found', ["The repo: #{Brightpearl::Terminal::format_directory(branch_data[:"#{Brightpearl::Git::BRANCH_LOCATION}"])}\x1B[38;5;240m doesn't have have a branch called #{Brightpearl::Terminal::format_branch(source_branch_name)}", "Because of this, branch for this repo will be cut from #{Brightpearl::Terminal::format_branch(Brightpearl::Git::MASTER)}\x1B[38;5;240m instead."])
74
+ sb = App::Git::MASTER
75
+ source_branch_final << App::Git::MASTER
76
+ if source_branch_name != App::Git::MASTER
77
+ App::Terminal::warning('Branch not found', ["The repo: #{App::Terminal::format_directory(branch_data[:"#{App::Git::BRANCH_LOCATION}"])}\x1B[38;5;240m doesn't have have a branch called #{App::Terminal::format_branch(source_branch_name)}", "Because of this, branch for this repo will be cut from #{App::Terminal::format_branch(App::Git::MASTER)}\x1B[38;5;240m instead."])
70
78
  end
71
79
  end
72
80
  commands = [
73
81
  "git checkout #{sb}"
74
82
  ]
75
- if branch_data[:"#{Brightpearl::Git::BRANCH_HAS_UPSTREAM}"]
83
+ if branch_data[:"#{App::Git::BRANCH_HAS_UPSTREAM}"]
76
84
  commands << 'git pull'
77
85
  end
78
86
  commands << "git checkout -b #{new_branch_name}"
79
87
  if push_to_origin
80
88
  commands << "git push --set-upstream origin #{new_branch_name}"
81
89
  end
82
- Brightpearl::Terminal::command(commands, branch_data[:"#{Brightpearl::Git::BRANCH_LOCATION}"])
90
+ App::Terminal::command(commands, branch_data[:"#{App::Git::BRANCH_LOCATION}"])
83
91
  end
84
92
 
85
93
  if source_branch_final[0] == source_branch_final[1]
@@ -87,9 +95,9 @@ module BrightpearlCommand
87
95
  else
88
96
  source_branch_final = "#{source_branch_final[0]}/#{source_branch_final[1]}"
89
97
  end
90
- Brightpearl::Terminal::success('Branch created', "Branch #{Brightpearl::Terminal::format_branch(new_branch_name)}\x1B[38;5;240m has been successfully cut from #{Brightpearl::Terminal::format_branch(source_branch_final)}")
98
+ App::Terminal::success('Branch created', "Branch #{App::Terminal::format_branch(new_branch_name)}\x1B[38;5;240m has been successfully cut from #{App::Terminal::format_branch(source_branch_final)}")
91
99
  else
92
- Brightpearl::Terminal::abort(nil, nil, true, false)
100
+ App::Terminal::abort(nil, nil, true, false)
93
101
  end
94
102
 
95
103
  end
@@ -97,48 +105,49 @@ module BrightpearlCommand
97
105
  # Checks out a branch for both /code & /db.
98
106
  # @return void
99
107
  def checkout_branch
108
+
100
109
  branch_to_checkout = @args[0]
101
110
  branch_data = @git.branch_data(branch_to_checkout)
111
+
102
112
  # If branch is already checked out.
103
- if branch_data[0][:"#{Brightpearl::Git::BRANCH_IS_CURRENT}"] && branch_data[1][:"#{Brightpearl::Git::BRANCH_IS_CURRENT}"]
104
- Brightpearl::Terminal::info("You are already on branch #{Brightpearl::Terminal::format_branch(branch_to_checkout)}")
113
+ if branch_data[0][:"#{App::Git::BRANCH_IS_CURRENT}"] && branch_data[1][:"#{App::Git::BRANCH_IS_CURRENT}"]
114
+ App::Terminal::info("You are already on branch #{App::Terminal::format_branch(branch_to_checkout)}")
105
115
  if @opts[:update] || @opts[:updatePush]
106
- Brightpearl::Terminal::info("To update the branch, run: #{Brightpearl::Terminal::format_command('bp g u')}", nil, false)
116
+ App::Terminal::info("To update the branch, run: #{App::Terminal::format_command('bp g u')}", nil, false)
107
117
  end
108
118
  @git.check_for_stash
109
119
  exit
110
120
  end
121
+
111
122
  # If branch doesn't exist.
112
- if branch_data[0][:"#{Brightpearl::Git::BRANCH_EXISTS}"] == false && branch_data[1][:"#{Brightpearl::Git::BRANCH_EXISTS}"] == false
113
- Brightpearl::Terminal::error("The branch you're trying to checkout #{Brightpearl::Terminal::format_branch(branch_to_checkout)} doesn't exist", 'Please check your spelling and try again.', true)
123
+ if branch_data[0][:"#{App::Git::BRANCH_EXISTS}"] == false && branch_data[1][:"#{App::Git::BRANCH_EXISTS}"] == false
124
+ App::Terminal::error("The branch you're trying to checkout #{App::Terminal::format_branch(branch_to_checkout)} doesn't exist", 'Please check your spelling and try again.', true)
114
125
  end
126
+
115
127
  @git.check_for_uncommitted_files
128
+
116
129
  count = 0
117
130
  branch_data.each do |branch_data_inner|
118
- repo_dir = branch_data_inner[:"#{Brightpearl::Git::BRANCH_LOCATION}"]
119
- if branch_data_inner[:"#{Brightpearl::Git::BRANCH_EXISTS}"] == false
131
+ repo_dir = branch_data_inner[:"#{App::Git::BRANCH_LOCATION}"]
132
+ if branch_data_inner[:"#{App::Git::BRANCH_EXISTS}"] == false
120
133
  next
121
134
  end
122
135
  commands = []
123
136
  if @opts[:update] || @opts[:updatePush]
124
- commands << "git checkout #{Brightpearl::Git::MASTER}"
137
+ commands << "git checkout #{App::Git::MASTER}"
125
138
  commands << 'git pull'
126
139
  end
127
- unless branch_data_inner[:"#{Brightpearl::Git::BRANCH_IS_CURRENT}"]
140
+ unless branch_data_inner[:"#{App::Git::BRANCH_IS_CURRENT}"]
128
141
  commands << "git checkout #{branch_to_checkout}"
129
142
  end
130
143
  if @opts[:update] || @opts[:updatePush]
131
- if branch_data[count][:"#{Brightpearl::Git::BRANCH_HAS_UPSTREAM}"]
132
- commands << 'git pull'
133
- else
134
- @git.ask_to_setup_remote_tracking(@git.current_branch_for_repo(repo_dir), repo_dir)
135
- end
136
- commands << "git merge #{Brightpearl::Git::MASTER}"
144
+ commands << 'git pull'
145
+ commands << "git merge #{App::Git::MASTER}"
137
146
  end
138
147
  if @opts[:updatePush]
139
148
  commands << 'git push'
140
149
  end
141
- Brightpearl::Terminal::command(commands, repo_dir)
150
+ App::Terminal::command(commands, repo_dir)
142
151
  count = count + 1
143
152
  end
144
153
  @git.check_for_same_branch
@@ -1,11 +1,12 @@
1
- module BrightpearlCommand
1
+ module AppCommand
2
2
 
3
3
  class GitDelete < ::Convoy::ActionCommand::Base
4
4
 
5
5
  def execute
6
+
6
7
  @opts = command_options
7
8
  @args = arguments
8
- @git = Brightpearl::Git.new
9
+ @git = App::Git.new
9
10
  opts_validate
10
11
  opts_routing
11
12
 
@@ -14,7 +15,7 @@ module BrightpearlCommand
14
15
  def opts_validate
15
16
 
16
17
  if @opts[:delete_local] == false && @opts[:delete_remote] == false && @opts[:delete_both] == false
17
- Brightpearl::Terminal::error('You must specify one of the following flags:', [
18
+ App::Terminal::error('You must specify one of the following flags:', [
18
19
  "-l --delete-local \xe2\x86\x92 Delete local branch",
19
20
  "-r --delete-remote \xe2\x86\x92 Delete remote branch",
20
21
  "-b --delete-both \xe2\x86\x92 Delete both local & remote branches"
@@ -23,7 +24,7 @@ module BrightpearlCommand
23
24
  end
24
25
 
25
26
  unless @args.any?
26
- @args[0] = @git.current_branch_for_repo(Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE))
27
+ @args[0] = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
27
28
  end
28
29
 
29
30
  if @args[0] == 'master'
@@ -36,70 +37,15 @@ module BrightpearlCommand
36
37
  def opts_routing
37
38
 
38
39
  if @opts[:delete_local]
39
- delete_local
40
+ App::GitDelete::delete_local(@args[0])
40
41
  elsif @opts[:delete_remote]
41
- delete_remote
42
+ App::GitDelete::delete_remote(@args[0])
42
43
  elsif @opts[:delete_both]
43
- delete_both
44
+ App::GitDelete::delete_both(@args[0])
44
45
  end
45
46
 
46
47
  end
47
48
 
48
- def delete_local
49
- Brightpearl::Terminal::output("Must check that branch is up-to-date with it's remote counter-part, otherwise DO NOT delete!", Brightpearl::Terminal::MSG_TODO)
50
- Brightpearl::Terminal::output('Must check branch even exists.', Brightpearl::Terminal::MSG_TODO)
51
- unless Brightpearl::Terminal::prompt_yes_no("#{Brightpearl::Terminal::format_action('locally delete')} branch #{Brightpearl::Terminal::format_branch(@args[0])}?")
52
- Brightpearl::Terminal::abort
53
- end
54
- @git.repo_loop.each do |repo_dir|
55
- commands = []
56
- if @git.current_branch_for_repo(repo_dir) == @args[0]
57
- commands << 'git checkout master'
58
- end
59
- commands << "git branch -d #{@args[0]}"
60
- Brightpearl::Terminal::command(commands, repo_dir)
61
- end
62
- Brightpearl::Terminal::success('Branch deleted', "Successfully #{Brightpearl::Terminal::format_highlight('locally')} #{Brightpearl::Terminal::format_action('deleted')} branch #{Brightpearl::Terminal::format_branch(@args[0])}")
63
- end
64
-
65
- def delete_remote
66
- Brightpearl::Terminal::output('Must check branch even exists.', Brightpearl::Terminal::MSG_TODO)
67
- unless Brightpearl::Terminal::prompt_yes_no("#{Brightpearl::Terminal::format_action('remotely delete')} branch #{Brightpearl::Terminal::format_branch(@args[0])}?")
68
- Brightpearl::Terminal::abort
69
- end
70
- @git.repo_loop.each do |repo_dir|
71
- unless @git.branch_exists(@args[0], repo_dir, Brightpearl::Git::REMOTE)
72
- puts "Branch \x1B[32m[#{@args[0]}]\x1B[0m not found in: \x1B[33m#{repo_dir}\x1B[0m. Aborting \x1B[35mREMOTE DELETE\x1B[0m for this repo."
73
- next
74
- end
75
- commands = [
76
- "git branch --unset-upstream #{@args[0]}",
77
- "git push origin --delete #{@args[0]}",
78
- ]
79
- Brightpearl::Terminal::command(commands, repo_dir)
80
- end
81
- Brightpearl::Terminal::success('Branch deleted', "Successfully #{Brightpearl::Terminal::format_highlight('remotely')} #{Brightpearl::Terminal::format_action('deleted')} branch #{Brightpearl::Terminal::format_branch(@args[0])}")
82
- end
83
-
84
- def delete_both
85
- Brightpearl::Terminal::output("Must check that branch is up-to-date with it's remote counter-part, otherwise DO NOT delete!", Brightpearl::Terminal::MSG_TODO)
86
- Brightpearl::Terminal::output('Must check branch even exists.', Brightpearl::Terminal::MSG_TODO)
87
- unless Brightpearl::Terminal::prompt_yes_no("#{Brightpearl::Terminal::format_action('locally & remotely delete')} branch #{Brightpearl::Terminal::format_branch(@args[0])}?")
88
- Brightpearl::Terminal::abort
89
- end
90
- @git.repo_loop.each do |repo_dir|
91
- commands = []
92
- if @git.current_branch_for_repo(repo_dir) == @args[0]
93
- commands << 'git checkout master'
94
- end
95
- commands << "git branch -d #{@args[0]}"
96
- commands << "git branch --unset-upstream #{@args[0]}"
97
- commands << "git push origin --delete #{@args[0]}"
98
- Brightpearl::Terminal::command(commands, repo_dir)
99
- end
100
- Brightpearl::Terminal::success('Branch deleted', "Successfully #{Brightpearl::Terminal::format_highlight('locally')} and #{Brightpearl::Terminal::format_highlight('remotely')} #{Brightpearl::Terminal::format_action('deleted')} branch #{Brightpearl::Terminal::format_branch(@args[0])}")
101
- end
102
-
103
49
  end
104
50
 
105
51
  end