Class: Paratrooper::SourceControl
- Inherits:
-
Object
- Object
- Paratrooper::SourceControl
- Extended by:
- Forwardable
- Defined in:
- lib/paratrooper/source_control.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #branch_name ⇒ Object
- #deployment_sha ⇒ Object
- #force_flag ⇒ Object
-
#initialize(config) ⇒ SourceControl
constructor
A new instance of SourceControl.
- #match_tag_name ⇒ Object
- #push_to_deploy ⇒ Object
- #reference_point ⇒ Object
- #remote ⇒ Object
- #scm_match_reference ⇒ Object
- #scm_tag_reference ⇒ Object
-
#system_call(cmd, exit_code = false) ⇒ Object
Internal: Calls commands meant to go to system.
- #tag_name ⇒ Object
- #taggable? ⇒ Boolean
- #untaggable? ⇒ Boolean
- #update_repo_tag ⇒ Object
Constructor Details
#initialize(config) ⇒ SourceControl
Returns a new instance of SourceControl.
10 11 12 |
# File 'lib/paratrooper/source_control.rb', line 10 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/paratrooper/source_control.rb', line 8 def config @config end |
Instance Method Details
#branch_name ⇒ Object
18 19 20 21 22 23 |
# File 'lib/paratrooper/source_control.rb', line 18 def branch_name if config.branch_name? branch = config.branch_name.to_s branch.upcase == "HEAD" ? "HEAD" : "refs/heads/#{config.branch_name}" end end |
#deployment_sha ⇒ Object
33 34 35 |
# File 'lib/paratrooper/source_control.rb', line 33 def deployment_sha system_call("git rev-parse #{reference_point}").strip end |
#force_flag ⇒ Object
37 38 39 |
# File 'lib/paratrooper/source_control.rb', line 37 def force_flag "-f " if config.force_push end |
#match_tag_name ⇒ Object
53 54 55 |
# File 'lib/paratrooper/source_control.rb', line 53 def match_tag_name config.match_tag_name end |
#push_to_deploy ⇒ Object
25 26 27 |
# File 'lib/paratrooper/source_control.rb', line 25 def push_to_deploy system_call("git push #{force_flag}#{remote} #{reference_point}:refs/heads/master", :exit_code) end |
#reference_point ⇒ Object
29 30 31 |
# File 'lib/paratrooper/source_control.rb', line 29 def reference_point tag_name || branch_name || 'HEAD' end |
#remote ⇒ Object
14 15 16 |
# File 'lib/paratrooper/source_control.rb', line 14 def remote "git@#{config.deployment_host}:#{config.app_name}.git" end |
#scm_match_reference ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/paratrooper/source_control.rb', line 61 def scm_match_reference if match_tag_name "refs/tags/#{match_tag_name}" else "HEAD" end end |
#scm_tag_reference ⇒ Object
57 58 59 |
# File 'lib/paratrooper/source_control.rb', line 57 def scm_tag_reference "refs/tags/#{tag_name}" if tag_name end |
#system_call(cmd, exit_code = false) ⇒ Object
Internal: Calls commands meant to go to system.
cmd - String version of system command.
78 79 80 |
# File 'lib/paratrooper/source_control.rb', line 78 def system_call(cmd, exit_code = false) system_caller.execute(cmd, exit_code) end |
#tag_name ⇒ Object
41 42 43 |
# File 'lib/paratrooper/source_control.rb', line 41 def tag_name config.tag_name end |
#taggable? ⇒ Boolean
45 46 47 |
# File 'lib/paratrooper/source_control.rb', line 45 def taggable? !untaggable? end |
#untaggable? ⇒ Boolean
49 50 51 |
# File 'lib/paratrooper/source_control.rb', line 49 def untaggable? tag_name.nil? || tag_name.empty? end |
#update_repo_tag ⇒ Object
69 70 71 72 |
# File 'lib/paratrooper/source_control.rb', line 69 def update_repo_tag system_call("git tag #{tag_name} #{match_tag_name} -f") system_call("git push -f origin #{scm_tag_reference}") end |