Sha256: d7bd0f61ee538d97cdf5d33c0a5f8498901c47111ad0cf78f486b75c9b66b036

Contents?: true

Size: 1.65 KB

Versions: 40

Compression:

Stored size: 1.65 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/#{QA::Release.new(release).api_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

40 entries across 40 versions & 1 rubygems

Version Path
gitlab-qa-6.21.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.21.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.20.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.20.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.19.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.18.2 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.18.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.18.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.17.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.17.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.16.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.15.4 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.15.3 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.15.2 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.15.1 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.15.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.14.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.13.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.12.0 lib/gitlab/qa/scenario/test/sanity/version.rb
gitlab-qa-6.11.0 lib/gitlab/qa/scenario/test/sanity/version.rb