ora-cli 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d45f1c3607059b4090480dfdfb27bef6542a7cbf
4
- data.tar.gz: 94f4f9e306a9836086863e142593bcdf31b92399
3
+ metadata.gz: f5a16980ec4decffb7553e61174d6accaf4d03a0
4
+ data.tar.gz: 93b52167a75ade9e723ec2104c39cafa3fbe2e13
5
5
  SHA512:
6
- metadata.gz: 0d3d333b86936299e5da26c9660f753580b960c553af976713aabdf7b8a61f145a2b2e80e62774181ac8407dd70794c6768876a11e559a84ab90fe8cfecade09
7
- data.tar.gz: 4c8901a6acfa2ad35c76e55f3c5ee147a0541710e4c74a595aced21992e13c0576763fecfba2a78e8190ae2707ffe45dc14aa0373db29e6b05fcd4f296badfb5
6
+ metadata.gz: 93d7c97aa498f86bfc5fe0885e89c43788e8ba89a4acfe83824cd8bd0a4d607dc98c0e2491f505b659a34a1a683754e9833a93d452e3d384ef8b27bc24264001
7
+ data.tar.gz: 853a503f7e487bdcc7c4e1841f95972e64c4ef15fdb6387bbf777f4a1f7e5135633ab37a358aa88cda9e73efb48abed354d4f89f778acf83bcc356c66d48acc6
data/bin/ora CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
3
 
3
4
  require 'ora/cli'
4
5
 
data/lib/ora/cli/bash.rb CHANGED
@@ -3,11 +3,14 @@ require "ora/cli/path"
3
3
 
4
4
  module Ora::Cli
5
5
  class Bash
6
+ attr_reader :unprocessed_commands
7
+
6
8
  def initialize(target, from: nil, print: Print.new)
7
- @target = target
8
- @from = from
9
- @print = print
10
- @success = true
9
+ @target = target
10
+ @from = from
11
+ @print = print
12
+ @success = true
13
+ @unprocessed_commands = []
11
14
  end
12
15
 
13
16
  def silent command
@@ -16,17 +19,24 @@ module Ora::Cli
16
19
 
17
20
  def run commands
18
21
  @success = true
19
- unprocessed_commands = extract commands
22
+ @unprocessed_commands = extract commands
20
23
 
21
24
  outputs = []
22
- while (command = complete unprocessed_commands.shift)
25
+ command = ''
26
+ while (command = complete @unprocessed_commands.shift)
23
27
  next if command.empty?
24
- break unless call command do |output|
28
+
29
+ if method? command
30
+ sub_commands = call_method command
31
+ @unprocessed_commands.unshift(*extract(sub_commands))
32
+ else
33
+ @success, output = shell command
25
34
  outputs.push output
35
+ break unless @success
26
36
  end
27
37
  end
28
38
 
29
- handle_failed unprocessed_commands
39
+ @unprocessed_commands.unshift(command) unless @success
30
40
 
31
41
  join outputs
32
42
  end
@@ -54,8 +64,8 @@ module Ora::Cli
54
64
  outputs.compact.map(&:strip).reject(&:empty?).join("\n")
55
65
  end
56
66
 
57
- def call_target method_name
58
- @target.method(method_name).call
67
+ def call_target method_name, args = []
68
+ @target.method(method_name).call(*args)
59
69
  end
60
70
 
61
71
  def complete unprocessed_command
@@ -66,45 +76,28 @@ module Ora::Cli
66
76
  end
67
77
  end
68
78
 
69
- def call command
79
+ def shell command
70
80
  @print.green command
71
81
 
72
- @success =
73
- if method? command
74
- call_method command
75
- else
76
- yield(shell command)
77
- $?.success?
78
- end
82
+ output = @print.plain `#{move}#{command}#{capture_err}`
83
+ success = $?.success?
79
84
 
80
- alert command unless @success
81
- @success
85
+ show_failed_message unless success
86
+
87
+ [success, output]
82
88
  end
83
89
  def method? command
84
90
  command.start_with? ":"
85
91
  end
86
- def method_name command
87
- command.sub(':', '')
88
- end
89
92
  def call_method command
90
- success_call? call_target(method_name command)
91
- end
92
- def success_call? method_return
93
- method_return != false
94
- end
95
- def shell command
96
- @print.plain `#{move}#{command}#{capture_err}`
97
- end
98
-
99
- def alert command
100
- @print.red "\nProcess Failed! Please resolve the issue above and run commands below manually\n"
101
- @print.red command
93
+ list = command.split
94
+ method = list.shift.sub(':', '')
95
+ args = list.join.split(',').map(&:strip)
96
+ call_target(method, args)
102
97
  end
103
98
 
104
- def handle_failed unprocessed_commands
105
- unprocessed_commands.each do |unprocessed_command|
106
- @print.red(complete unprocessed_command)
107
- end
99
+ def show_failed_message
100
+ @print.red "\nProcess Failed! Please resolve the issue above and run 'ora' again to continue\n"
108
101
  end
109
102
 
110
103
  end
@@ -0,0 +1,4 @@
1
+ module Ora::Cli
2
+ class PreconditionError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,34 @@
1
+ require 'ora/cli/task'
2
+
3
+ module Ora::Cli
4
+ class PushTask < Task
5
+
6
+ def commands
7
+ '
8
+ :feature_branch!
9
+ :clean_branch!
10
+ :pull_branch
11
+ git checkout develop
12
+ git pull origin develop
13
+ git checkout #{branch}
14
+ git merge develop
15
+ git checkout #{target}
16
+ git pull origin #{target}
17
+ git merge #{branch}
18
+ git push origin #{target}
19
+ git checkout #{branch}
20
+ :slack_message_to_paste
21
+ '
22
+ end
23
+
24
+ private
25
+ def slack_message_to_paste
26
+ print.plain ":merge: #{branch} => #{target}\n:monorail: #{target}"
27
+ ''
28
+ end
29
+
30
+ def target
31
+ self.class.name.match(/PushTo(.*)/)[1].downcase
32
+ end
33
+ end
34
+ end
data/lib/ora/cli/task.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  require "ora/cli/bash"
2
2
  require "ora/cli/print"
3
3
  require "ora/cli/stdin"
4
+ require 'ora/cli/precondition_error'
5
+ require "json"
4
6
 
5
7
  module Ora::Cli
6
8
  class Task
7
9
  attr_reader :branch, :stdin, :print
8
10
 
9
- MAIN_BRANCHES = %w{master develop staging uat}
11
+ DEVELOP_BRANCH = 'develop'
12
+ CONTINUE_FILE = '~/.ora_continue'
10
13
 
11
14
  def initialize(from, inputs: [], print: Print.new)
12
15
  @from = from
@@ -18,10 +21,36 @@ module Ora::Cli
18
21
 
19
22
  def run
20
23
  @bash.run commands
24
+ save_on_fail
25
+ rescue PreconditionError => e
26
+ @print.red("Precondition not met!\n#{e.message}")
27
+ end
28
+
29
+ def continue(info)
30
+ @print.green("Continue task - #{info['task']}\n")
31
+ set_variables(info['variables'])
32
+ @bash.run info['commands']
33
+ save_on_fail
34
+ File.delete(File.expand_path(CONTINUE_FILE)) if @bash.success?
35
+ end
36
+
37
+ def variables
38
+ instance_variables.inject({}) do |hash, attribute|
39
+ value = instance_variable_get(attribute)
40
+ if value.to_s.start_with? '#<'
41
+ hash
42
+ else
43
+ hash.merge!(attribute.to_s.sub('@', '') => value)
44
+ end
45
+ end
46
+ end
47
+
48
+ def set_variables data
49
+ data.each { |k, v| instance_variable_set("@#{k}", v) }
21
50
  end
22
51
 
23
52
  def commands
24
- raise "Override this method in subclass"
53
+ raise PreconditionError, "Override this method in subclass."
25
54
  end
26
55
 
27
56
  def success?
@@ -34,24 +63,64 @@ module Ora::Cli
34
63
  end
35
64
 
36
65
  def main_branch?
37
- MAIN_BRANCHES.include? branch
66
+ main_branches.include? branch
67
+ end
68
+
69
+ def main_branches
70
+ [DEVELOP_BRANCH] +
71
+ Dir.entries(Path.tasks).
72
+ map {|name| name.match(/push_to_(.*)\.rb/)}.compact.
73
+ map {|match| match[1]}
38
74
  end
39
75
 
40
76
  def feature_branch!
41
77
  if main_branch?
42
- @print.red "Please checkout feature branch first!"
43
- false
78
+ raise PreconditionError, "Please checkout feature branch first."
44
79
  end
80
+ ''
45
81
  end
46
82
 
47
83
  def clean_branch!
48
84
  if dirty?
49
- print.red "Please clean the feature branch '#{branch}'!"
50
- return false
85
+ raise PreconditionError,
86
+ "Please clean the feature branch '#{branch}'."
51
87
  end
88
+ ''
52
89
  end
53
90
  def dirty?
54
91
  !@bash.silent('git status').include? 'nothing to commit'
55
92
  end
93
+
94
+ def pull_branch
95
+ return '' unless remote_branch?
96
+
97
+ "git pull origin #{branch}"
98
+ end
99
+ def remote_branch?
100
+ !@bash.silent("git branch -a | grep remotes/origin/#{branch}$").empty?
101
+ end
102
+
103
+ def save_on_fail
104
+ return if @bash.success?
105
+
106
+ text = JSON.generate(
107
+ 'task' => underscore(self.class.name.split(':').last),
108
+ 'variables' => variables,
109
+ 'commands' => @bash.unprocessed_commands.join("\n")
110
+ )
111
+ File.write(File.expand_path(CONTINUE_FILE), text)
112
+ end
113
+
114
+ # File activesupport/lib/active_support/inflector/methods.rb
115
+ def underscore(camel_cased_word)
116
+ return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
117
+ word = camel_cased_word.to_s.gsub('::'.freeze, '/'.freeze)
118
+ # word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'.freeze }#{$2.downcase}" }
119
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
120
+ word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
121
+ word.tr!("-".freeze, "_".freeze)
122
+ word.downcase!
123
+ word
124
+ end
56
125
  end
57
126
  end
@@ -18,6 +18,7 @@ module Ora::Cli
18
18
  def set_branch_name
19
19
  print.inline 'Type new branch name: '
20
20
  @branch_name = stdin.gets(/^[a-zA-Z0-9\/_-]+$/)
21
+ ''
21
22
  end
22
23
  end
23
24
  end
@@ -6,6 +6,7 @@ module Ora::Cli
6
6
  '
7
7
  :feature_branch!
8
8
  :clean_branch!
9
+ :pull_branch
9
10
  git checkout develop
10
11
  git pull origin develop
11
12
  git checkout #{branch}
@@ -0,0 +1,6 @@
1
+ require 'ora/cli/push_task'
2
+
3
+ module Ora::Cli
4
+ class PushToAus < PushTask
5
+ end
6
+ end
@@ -8,6 +8,7 @@ module Ora::Cli
8
8
  '
9
9
  :feature_branch!
10
10
  :clean_branch!
11
+ :pull_branch
11
12
  git checkout develop
12
13
  git pull origin develop
13
14
  git merge #{branch}
@@ -33,6 +34,7 @@ module Ora::Cli
33
34
  print.inline "New Version: "
34
35
  @version = stdin.gets(/^(v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)?$/)
35
36
  @version = recommend_version if @version.empty?
37
+ ''
36
38
  end
37
39
  def latest_versions
38
40
  @latest_versions ||=
@@ -48,6 +50,7 @@ module Ora::Cli
48
50
 
49
51
  def slack_message_to_paste
50
52
  print.plain ":merge: #{branch} => develop\n:merge: develop => master\n:monorail: production"
53
+ ''
51
54
  end
52
55
  end
53
56
  end
@@ -1,28 +1,6 @@
1
- require 'ora/cli/task'
1
+ require 'ora/cli/push_task'
2
2
 
3
3
  module Ora::Cli
4
- class PushToStaging < Task
5
-
6
- def commands
7
- '
8
- :feature_branch!
9
- :clean_branch!
10
- git checkout develop
11
- git pull origin develop
12
- git checkout #{branch}
13
- git merge develop
14
- git checkout staging
15
- git pull origin staging
16
- git merge #{branch}
17
- git push origin staging
18
- git checkout #{branch}
19
- :slack_message_to_paste
20
- '
21
- end
22
-
23
- private
24
- def slack_message_to_paste
25
- print.plain ":merge: #{branch} => staging\n:monorail: staging"
26
- end
4
+ class PushToStaging < PushTask
27
5
  end
28
6
  end
@@ -1,28 +1,6 @@
1
- require 'ora/cli/task'
1
+ require 'ora/cli/push_task'
2
2
 
3
3
  module Ora::Cli
4
- class PushToUat < Task
5
-
6
- def commands
7
- '
8
- :feature_branch!
9
- :clean_branch!
10
- git checkout develop
11
- git pull origin develop
12
- git checkout #{branch}
13
- git merge develop
14
- git checkout uat
15
- git pull origin uat
16
- git merge #{branch}
17
- git push origin uat
18
- git checkout #{branch}
19
- :slack_message_to_paste
20
- '
21
- end
22
-
23
- private
24
- def slack_message_to_paste
25
- print.plain ":merge: #{branch} => uat\n:monorail: uat"
26
- end
4
+ class PushToUat < PushTask
27
5
  end
28
6
  end
@@ -1,4 +1,5 @@
1
1
  require 'ora/cli/task'
2
+ require 'ora/cli/precondition_error'
2
3
 
3
4
  module Ora::Cli
4
5
  class SwitchBranch < Task
@@ -10,24 +11,26 @@ module Ora::Cli
10
11
  :switch_to
11
12
  git stash save -u "OraCli"
12
13
  git checkout #{target_branch}
13
- #{apply_stash}
14
+ :apply_stash
14
15
  '
15
16
  end
16
17
 
17
18
  private
18
19
  def only_feature_branch_can_be_dirty!
19
20
  if main_branch? && dirty?
20
- print.red "#{branch} branch can't be dirty!"
21
- return false
21
+ raise PreconditionError, "#{branch} branch can't be dirty."
22
22
  end
23
+ ''
23
24
  end
24
25
 
25
26
  def switch_to
26
27
  @target_branch = stdin.select("git branch | grep '^ ' | sed 's/^ //'")
28
+ ''
27
29
  end
28
30
 
29
31
  def apply_stash
30
- return nil if target_stash_revision.empty?
32
+ return '' if target_stash_revision.empty?
33
+
31
34
  "git stash pop #{target_stash_revision}"
32
35
  end
33
36
  def target_stash_revision
@@ -1,5 +1,5 @@
1
1
  module Ora
2
2
  module Cli
3
- VERSION = "0.1.7"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
data/lib/ora/cli.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "ora/cli/version"
2
2
  require "ora/cli/bash"
3
3
  require "ora/cli/path"
4
+ require "ora/cli/task"
4
5
 
5
6
  module Ora
6
7
  module Cli
@@ -8,6 +9,20 @@ module Ora
8
9
  project_path = `pwd`.strip
9
10
  remove_ext = "sed 's/\.[^.]*$//'"
10
11
 
12
+ unless `cat #{Task::CONTINUE_FILE}`.empty?
13
+ continue = JSON.parse(File.read(File.expand_path(Task::CONTINUE_FILE)))
14
+
15
+ task = continue['task']
16
+ require "ora/cli/tasks/#{task}"
17
+
18
+ class_name = task.split('_').map(&:capitalize).join
19
+ Object.const_get("Ora::Cli::#{class_name}").
20
+ new(project_path).
21
+ continue(continue)
22
+
23
+ return
24
+ end
25
+
11
26
  task = Bash.new(project_path).select("ls #{Path.tasks} | #{remove_ext}")
12
27
 
13
28
  require "ora/cli/tasks/#{task}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ora-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ducksan Cho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-05 00:00:00.000000000 Z
11
+ date: 2016-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,11 +75,14 @@ files:
75
75
  - lib/ora/cli.rb
76
76
  - lib/ora/cli/bash.rb
77
77
  - lib/ora/cli/path.rb
78
+ - lib/ora/cli/precondition_error.rb
78
79
  - lib/ora/cli/print.rb
80
+ - lib/ora/cli/push_task.rb
79
81
  - lib/ora/cli/stdin.rb
80
82
  - lib/ora/cli/task.rb
81
83
  - lib/ora/cli/tasks/new_feature_branch.rb
82
84
  - lib/ora/cli/tasks/push_feature_branch.rb
85
+ - lib/ora/cli/tasks/push_to_aus.rb
83
86
  - lib/ora/cli/tasks/push_to_master.rb
84
87
  - lib/ora/cli/tasks/push_to_staging.rb
85
88
  - lib/ora/cli/tasks/push_to_uat.rb