diff options
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa.rb | 3 | ||||
-rw-r--r-- | qa/qa/git/repository.rb | 11 | ||||
-rw-r--r-- | qa/qa/page/project/settings/repository.rb | 2 | ||||
-rw-r--r-- | qa/qa/resource/repository/push.rb | 44 | ||||
-rw-r--r-- | qa/qa/resource/tag.rb | 30 | ||||
-rw-r--r-- | qa/qa/resource/user_gpg.rb | 46 | ||||
-rw-r--r-- | qa/qa/runtime/gpg.rb | 37 | ||||
-rw-r--r-- | qa/qa/runtime/user.rb | 4 |
8 files changed, 162 insertions, 15 deletions
@@ -23,6 +23,7 @@ module QA autoload :Feature, 'qa/runtime/feature' autoload :Fixtures, 'qa/runtime/fixtures' autoload :Logger, 'qa/runtime/logger' + autoload :GPG, 'qa/runtime/gpg' module API autoload :Client, 'qa/runtime/api/client' @@ -67,7 +68,9 @@ module QA autoload :Fork, 'qa/resource/fork' autoload :SSHKey, 'qa/resource/ssh_key' autoload :Snippet, 'qa/resource/snippet' + autoload :Tag, 'qa/resource/tag' autoload :ProjectMember, 'qa/resource/project_member' + autoload :UserGPG, 'qa/resource/user_gpg' module Events autoload :Base, 'qa/resource/events/base' diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 24b9fc67dd9..09052a5e33f 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -14,7 +14,7 @@ module QA include Scenario::Actable RepositoryCommandError = Class.new(StandardError) - attr_writer :use_lfs + attr_writer :use_lfs, :gpg_key_id attr_accessor :env_vars InvalidCredentialsError = Class.new(RuntimeError) @@ -25,6 +25,7 @@ module QA # .netrc can be utilised self.env_vars = [%Q{HOME="#{tmp_home_dir}"}] @use_lfs = false + @gpg_key_id = nil end def self.perform(*args) @@ -99,10 +100,18 @@ module QA git_lfs_track_result.to_s + git_add_result.to_s end + def delete_tag(tag_name) + run(%Q{git push origin --delete #{tag_name}}).to_s + end + def commit(message) run(%Q{git commit -m "#{message}"}).to_s end + def commit_with_gpg(message) + run(%Q{git config user.signingkey #{@gpg_key_id} && git config gpg.program $(which gpg) && git commit -S -m "#{message}"}).to_s + end + def push_changes(branch = 'master') run("git push #{uri} #{branch}").to_s end diff --git a/qa/qa/page/project/settings/repository.rb b/qa/qa/page/project/settings/repository.rb index 437a945aceb..506e70a180c 100644 --- a/qa/qa/page/project/settings/repository.rb +++ b/qa/qa/page/project/settings/repository.rb @@ -47,3 +47,5 @@ module QA end end end + +QA::Page::Project::Settings::Repository.prepend_if_ee('QA::EE::Page::Project::Settings::Repository') diff --git a/qa/qa/resource/repository/push.rb b/qa/qa/resource/repository/push.rb index a5827fb6e73..68674248be2 100644 --- a/qa/qa/resource/repository/push.rb +++ b/qa/qa/resource/repository/push.rb @@ -8,9 +8,9 @@ module QA class Push < Base attr_accessor :file_name, :file_content, :commit_message, :branch_name, :new_branch, :output, :repository_http_uri, - :repository_ssh_uri, :ssh_key, :user, :use_lfs + :repository_ssh_uri, :ssh_key, :user, :use_lfs, :tag_name - attr_writer :remote_branch + attr_writer :remote_branch, :gpg_key_id def initialize @file_name = 'file.txt' @@ -21,6 +21,8 @@ module QA @repository_http_uri = "" @ssh_key = nil @use_lfs = false + @tag_name = nil + @gpg_key_id = nil end def remote_branch @@ -67,29 +69,43 @@ module QA email = user.email end + unless @gpg_key_id.nil? + repository.gpg_key_id = @gpg_key_id + end + @output += repository.clone repository.configure_identity(username, email) @output += repository.checkout(branch_name, new_branch: new_branch) - if @directory - @directory.each_child do |f| - @output += repository.add_file(f.basename, f.read) if f.file? - end - elsif @files - @files.each do |f| - repository.add_file(f[:name], f[:content]) - end + if @tag_name + @output += repository.delete_tag(@tag_name) else - @output += repository.add_file(file_name, file_content) - end + if @directory + @directory.each_child do |f| + @output += repository.add_file(f.basename, f.read) if f.file? + end + elsif @files + @files.each do |f| + repository.add_file(f[:name], f[:content]) + end + else + @output += repository.add_file(file_name, file_content) + end - @output += repository.commit(commit_message) - @output += repository.push_changes("#{branch_name}:#{remote_branch}") + @output += commit_to repository + @output += repository.push_changes("#{branch_name}:#{remote_branch}") + end repository.delete_ssh_key end end + + private + + def commit_to(repository) + @gpg_key_id.nil? ? repository.commit(@commit_message) : repository.commit_with_gpg(@commit_message) + end end end end diff --git a/qa/qa/resource/tag.rb b/qa/qa/resource/tag.rb new file mode 100644 index 00000000000..ac4fccec525 --- /dev/null +++ b/qa/qa/resource/tag.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module QA + module Resource + class Tag < Base + attr_accessor :project, :name, :ref + + def resource_web_url(resource) + super + rescue ResourceURLMissingError + # this particular resource does not expose a web_url property + end + + def api_get_path + "/projects/#{project.id}/repository/tags/#{name}" + end + + def api_post_path + "/projects/#{project.id}/repository/tags" + end + + def api_post_body + { + tag_name: name, + ref: ref + } + end + end + end +end diff --git a/qa/qa/resource/user_gpg.rb b/qa/qa/resource/user_gpg.rb new file mode 100644 index 00000000000..25d74ad8ce5 --- /dev/null +++ b/qa/qa/resource/user_gpg.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +module QA + module Resource + class UserGPG < Base + attr_accessor :id, :gpg + attr_reader :key_id + + def initialize + @gpg = Runtime::GPG.new + @key_id = @gpg.key_id + end + + def fabricate_via_api! + super + @id = self.api_response[:id] + rescue ResourceFabricationFailedError => error + if error.message.include? 'has already been taken' + self + else + raise ResourceFabricationFailedError error + end + end + + def resource_web_url(resource) + super + rescue ResourceURLMissingError + # this particular resource does not expose a web_url property + end + + def api_get_path + "/user/gpg_keys/#{@id}" + end + + def api_post_path + '/user/gpg_keys' + end + + def api_post_body + { + key: @gpg.key + } + end + end + end +end diff --git a/qa/qa/runtime/gpg.rb b/qa/qa/runtime/gpg.rb new file mode 100644 index 00000000000..9f8baf7e580 --- /dev/null +++ b/qa/qa/runtime/gpg.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module QA + module Runtime + class GPG + attr_reader :key, :key_id + + def initialize + @key_id = 'B8358D73048DACC4' + import_key(File.expand_path('qa/ee/fixtures/gpg/admin.asc')) + @key = collect_key.first + end + + private + + def import_key(path) + import_key = "gpg --import #{path}" + execute(import_key) + end + + def collect_key + get_ascii_format = "gpg --armor --export #{@key_id}" + execute(get_ascii_format) + end + + def execute(command) + Open3.capture2e(*command) do |stdin, out, wait| + out.each_char { |char| print char } + + if wait.value.exited? && wait.value.exitstatus.nonzero? + raise CommandError, "Command `#{command}` failed!" + end + end + end + end + end +end diff --git a/qa/qa/runtime/user.rb b/qa/qa/runtime/user.rb index 011e4a548a5..3c26a3ad691 100644 --- a/qa/qa/runtime/user.rb +++ b/qa/qa/runtime/user.rb @@ -25,6 +25,10 @@ module QA Runtime::Env.user_password || default_password end + def email + default_email + end + def ldap_user? Runtime::Env.ldap_username && Runtime::Env.ldap_password end |