Class: Gitlab::QA::Component::Staging::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/qa/component/staging.rb

Instance Method Summary collapse

Constructor Details

#initialize(address) ⇒ Version

Returns a new instance of Version.



47
48
49
# File 'lib/gitlab/qa/component/staging.rb', line 47

def initialize(address)
  @uri = URI.join(address, '/api/v4/version')
end

Instance Method Details

#fetch!Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gitlab/qa/component/staging.rb', line 51

def fetch!
  response =
    Net::HTTP.start(@uri.host, @uri.port, use_ssl: true) do |http|
      http.request(request)
    end

  case response
  when Net::HTTPSuccess
    JSON.parse(response.body)
  else
    raise InvalidResponseError.new(@uri.to_s, response)
  end
end

#major_minor_revisionObject



65
66
67
68
69
70
71
# File 'lib/gitlab/qa/component/staging.rb', line 65

def major_minor_revision
  api_response = fetch!
  version_regexp = /^v?(?<major>\d+)\.(?<minor>\d+)\.\d+/
  match = version_regexp.match(api_response.fetch('version'))

  "#{match[:major]}.#{match[:minor]}-#{api_response.fetch('revision')}"
end