Sha256: 6cf6c5a61c9d92f247a2965858405345d9e5185e27e1cbc9e196be510bc42291

Contents?: true

Size: 1.64 KB

Versions: 88

Compression:

Stored size: 1.64 KB

Contents

require 'json'
require 'net/http'
require 'cgi'

module Gitlab
  module QA
    module Scenario
      module Test
        module Sanity
          # This test checks that the sha_version of a GitLab was authored in
          # the window defined by `HOURS_AGO`.  We perform a single API call,
          # so `COMMITS` needs to be a large enough value that we expect all
          # the commits in the time window will fit.
          class Version < Scenario::Template
            HOURS_AGO = 24
            COMMITS = 10_000

            def perform(release)
              version = Component::Gitlab.perform do |gitlab|
                gitlab.release = release
                gitlab.act do
                  pull
                  sha_version
                end
              end

              project = "gitlab-org/#{Release.new(release).project_name}"
              commit = recent_commits(project).find { |c| c['id'] == version }

              if commit
                puts "Found commit #{version} in recent history of #{project}"
              else
                puts "Did not find #{version} in recent history of #{project}"
                exit 1
              end
            end

            private

            def recent_commits(project)
              api = 'https://gitlab.com/api/v4'
              url = "#{api}/projects/#{CGI.escape(project)}/repository/commits"
              since = (Time.now - HOURS_AGO * 60 * 60).strftime('%FT%T')

              uri = URI(url)
              uri.query = URI.encode_www_form(since: since, per_page: COMMITS)
              JSON.parse(Net::HTTP.get(uri))
            end
          end
        end
      end
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
gitlab-qa-5.13.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.13.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.12.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.10.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.10.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.9.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.8.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.8.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.7.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.6.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.6.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.5.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.4.3 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.4.2 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.4.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.4.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.3.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.2.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.1.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-5.1.0 lib/gitlab/qa/scenario/test/sanity/version.rb