Class: Solano::SCM
- Inherits:
-
Object
- Object
- Solano::SCM
- Defined in:
- lib/solano/scm.rb,
lib/solano/scm/scm.rb,
lib/solano/scm/url.rb,
lib/solano/scm/configure.rb
Constant Summary collapse
- SCMS =
%w(git hg)
Instance Attribute Summary collapse
-
#default_origin_url ⇒ Object
Returns the value of attribute default_origin_url.
Class Method Summary collapse
- .configure ⇒ Object
- .parse_scp_url(url, scp_path) ⇒ Object
-
.scp_url?(raw_url, attempted_parse) ⇒ Boolean
Returns scp path if it looks like this is an SCP url.
-
.valid_repo_url?(url) ⇒ Boolean
Weak validator; server will also validate.
- .without_scheme(url, scheme = nil) ⇒ Object
Instance Method Summary collapse
- #changes?(options = {}) ⇒ Boolean
- #commits ⇒ Object
- #create_patch(session_id, options = {}) ⇒ Object
- #create_snapshot(session_id, options = {}) ⇒ Object
- #current_branch ⇒ Object
- #current_commit ⇒ Object
- #default_branch ⇒ Object
- #get_snap_id ⇒ Object
- #ignore_path ⇒ Object
-
#initialize ⇒ SCM
constructor
A new instance of SCM.
- #latest_commit ⇒ Object
- #number_of_commits(id_from, id_to) ⇒ Object
- #origin_url ⇒ Object
- #push_latest(session_data, suite_details, options = {}) ⇒ Object
- #repo? ⇒ Boolean
- #repo_name ⇒ Object
- #root ⇒ Object
- #scm_name ⇒ Object
- #support_data ⇒ Object
- #upload_file(auth_url, file_path) ⇒ Object
Constructor Details
#initialize ⇒ SCM
Returns a new instance of SCM.
8 9 10 |
# File 'lib/solano/scm/scm.rb', line 8 def initialize @default_origin_url = nil end |
Instance Attribute Details
#default_origin_url ⇒ Object
Returns the value of attribute default_origin_url.
6 7 8 |
# File 'lib/solano/scm/scm.rb', line 6 def default_origin_url @default_origin_url end |
Class Method Details
.configure ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/solano/scm/configure.rb', line 5 def self.configure scm = nil ok = false scms = [::Solano::Git, ::Solano::Hg] # Select SCM based on command availability and current repo type scms.each do |scm_class| sniff_scm = scm_class.new if sniff_scm.repo? && scm_class.version_ok then ok = true scm = sniff_scm break end end # Fall back to first SCM type that is available if !ok then scms.each do |scm_class| sniff_scm = scm_class.new if scm_class.version_ok then ok = true scm = sniff_scm break end end end # Default to a null SCM implementation scm ||= ::Solano::StubSCM.new return [scm, ok] end |
.parse_scp_url(url, scp_path) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/solano/scm/url.rb', line 7 def self.parse_scp_url(url, scp_path) # remove the ssh scheme (if any) url_to_parse = without_scheme(url, "ssh") # This is a gross abuse of Adressable::URI # It will treat [email protected] in [email protected]:user/repo.git as a scheme uri = Addressable::URI.parse(url_to_parse) raise SolanoError.new("invalid repo url #{url}") if uri.scheme.nil? scheme_parts = uri.scheme.split("@") uri.path = "/#{uri.path}" unless uri.path.to_s[0] == "/" uri.scheme = "ssh" uri.host = scheme_parts.last uri.user = scheme_parts.first uri end |
.scp_url?(raw_url, attempted_parse) ⇒ Boolean
Returns scp path if it looks like this is an SCP url
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/solano/scm/url.rb', line 25 def self.scp_url?(raw_url, attempted_parse) if attempted_parse && attempted_parse.scheme == 'https' then return nil end raw_url_elements = without_scheme(raw_url).split(":") scp_path = raw_url_elements.last if raw_url_elements.size > 1 if scp_path then path_elements = scp_path.split(/\//) return scp_path if path_elements[0] !~ /^\d+$/ end return nil end |
.valid_repo_url?(url) ⇒ Boolean
Weak validator; server will also validate
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/solano/scm/url.rb', line 44 def self.valid_repo_url?(url) if url.nil? || url.strip.empty? then raise SolanoError.new("invalid empty scm url") end begin attempted_parse = Addressable::URI.parse(url) rescue Exception => e raise SolanoError.new(e.) end if scp_path = scp_url?(url, attempted_parse) then uri = parse_scp_url(url, scp_path) else uri = attempted_parse end scheme_pattern = SCMS+SCMS.map { |scm| scm+"+ssh" } scheme_pattern = scheme_pattern.join("|") scheme_pattern = "https?|ssh|"+scheme_pattern ok = uri.scheme =~ /^(#{scheme_pattern})$/ ok &&= uri.host && uri.host.size > 0 ok &&= uri.path && uri.path.size > 0 if !ok then raise SolanoError.new("invalid repo url: '#{url}'") end return ok end |
.without_scheme(url, scheme = nil) ⇒ Object
38 39 40 41 |
# File 'lib/solano/scm/url.rb', line 38 def self.without_scheme(url, scheme = nil) scheme ||= "[a-z]+" url.gsub(/^#{scheme}\:\/\//, "") end |
Instance Method Details
#changes?(options = {}) ⇒ Boolean
65 66 67 |
# File 'lib/solano/scm/scm.rb', line 65 def changes?(={}) return false end |
#commits ⇒ Object
108 109 110 |
# File 'lib/solano/scm/scm.rb', line 108 def commits [] end |
#create_patch(session_id, options = {}) ⇒ Object
81 82 83 |
# File 'lib/solano/scm/scm.rb', line 81 def create_patch(session_id, ={}) raise Text::Error:PATCH_NOT_SUPPORTED end |
#create_snapshot(session_id, options = {}) ⇒ Object
77 78 79 |
# File 'lib/solano/scm/scm.rb', line 77 def create_snapshot(session_id, ={}) raise Text::Error:SNAPSHOT_NOT_SUPPORTED end |
#current_branch ⇒ Object
57 58 59 |
# File 'lib/solano/scm/scm.rb', line 57 def current_branch return nil end |
#current_commit ⇒ Object
104 105 106 |
# File 'lib/solano/scm/scm.rb', line 104 def current_commit return nil end |
#default_branch ⇒ Object
61 62 63 |
# File 'lib/solano/scm/scm.rb', line 61 def default_branch return nil end |
#get_snap_id ⇒ Object
69 70 71 |
# File 'lib/solano/scm/scm.rb', line 69 def get_snap_id return @snap_id end |
#ignore_path ⇒ Object
53 54 55 |
# File 'lib/solano/scm/scm.rb', line 53 def ignore_path return nil end |
#latest_commit ⇒ Object
116 117 118 |
# File 'lib/solano/scm/scm.rb', line 116 def latest_commit return nil end |
#number_of_commits(id_from, id_to) ⇒ Object
112 113 114 |
# File 'lib/solano/scm/scm.rb', line 112 def number_of_commits(id_from, id_to) return 0 end |
#origin_url ⇒ Object
49 50 51 |
# File 'lib/solano/scm/scm.rb', line 49 def origin_url return @default_origin_url end |
#push_latest(session_data, suite_details, options = {}) ⇒ Object
73 74 75 |
# File 'lib/solano/scm/scm.rb', line 73 def push_latest(session_data, suite_details, ={}) return false end |
#repo? ⇒ Boolean
37 38 39 |
# File 'lib/solano/scm/scm.rb', line 37 def repo? return false end |
#repo_name ⇒ Object
45 46 47 |
# File 'lib/solano/scm/scm.rb', line 45 def repo_name return "unknown" end |
#root ⇒ Object
41 42 43 |
# File 'lib/solano/scm/scm.rb', line 41 def root return Dir.pwd end |
#scm_name ⇒ Object
34 35 |
# File 'lib/solano/scm/scm.rb', line 34 def scm_name end |
#support_data ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/solano/scm/scm.rb', line 12 def support_data data = Hash.new data['scm_name'] = self.scm_name if !self.repo? then data['is_repo'] = false return data end %w(scm_name repo? root repo_name origin_url current_branch default_branch changes?).each do |method| key = method if method =~ /[?]\z/ then key = "is_#{method.sub(/[?]\z/, '')}" end value = self.send(method.to_sym) rescue nil data[key] = value end return data end |
#upload_file(auth_url, file_path) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/solano/scm/scm.rb', line 85 def upload_file(auth_url, file_path) if (`which curl >/dev/null 2>&1 ; echo $?`).to_i == 0 then `curl -f --upload-file "#{file_path}" "#{auth_url}"` if(`echo $?`).to_i == 22 then raise "Failed to upload #{file_path} URL (#{out.code})" end else uri = URI(auth_url) body = File.read(file_path) out = Net::HTTP.start(uri.host, :use_ssl => true) do |http| http.send_request("PUT", uri.request_uri, body, {"content-type" => "",}) end if out.code.to_i != 200 raise "Failed to upload to #{file_path} (#{out.code})" end end end |