diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-11-02 17:32:28 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-11-05 22:20:57 +0800 |
commit | 4d0fd75cd5ceda72692a229d27ab6891fa8082e0 (patch) | |
tree | 7448b28ca974c9480e1e96b0d90c1322eeb9f0c7 /qa/qa/resource/repository | |
parent | c12a4a9ac7c04a215adf6062fec7bf31231c7d4a (diff) | |
download | gitlab-ce-4d0fd75cd5ceda72692a229d27ab6891fa8082e0.tar.gz |
Rename QA::Factory to QA::Resource53224-rename-to-resource-base-qa
* Factory::Base -> Resource::Base, and therefore:
* Factory::Resource::Project -> Resource::Project
Diffstat (limited to 'qa/qa/resource/repository')
-rw-r--r-- | qa/qa/resource/repository/project_push.rb | 44 | ||||
-rw-r--r-- | qa/qa/resource/repository/push.rb | 93 | ||||
-rw-r--r-- | qa/qa/resource/repository/wiki_push.rb | 36 |
3 files changed, 173 insertions, 0 deletions
diff --git a/qa/qa/resource/repository/project_push.rb b/qa/qa/resource/repository/project_push.rb new file mode 100644 index 00000000000..c9fafe3419f --- /dev/null +++ b/qa/qa/resource/repository/project_push.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +module QA + module Resource + module Repository + class ProjectPush < Repository::Push + attribute :project do + Project.fabricate! do |resource| + resource.name = 'project-with-code' + resource.description = 'Project with repository' + end + end + + def initialize + @file_name = 'file.txt' + @file_content = '# This is test project' + @commit_message = "This is a test commit" + @branch_name = 'master' + @new_branch = true + end + + def repository_http_uri + @repository_http_uri ||= begin + project.visit! + Page::Project::Show.act do + choose_repository_clone_http + repository_location.uri + end + end + end + + def repository_ssh_uri + @repository_ssh_uri ||= begin + project.visit! + Page::Project::Show.act do + choose_repository_clone_ssh + repository_location.uri + end + end + end + end + end + end +end diff --git a/qa/qa/resource/repository/push.rb b/qa/qa/resource/repository/push.rb new file mode 100644 index 00000000000..c14d97ff7fb --- /dev/null +++ b/qa/qa/resource/repository/push.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +require 'pathname' + +module QA + module Resource + module Repository + 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 + + attr_writer :remote_branch + + def initialize + @file_name = 'file.txt' + @file_content = '# This is test file' + @commit_message = "This is a test commit" + @branch_name = 'master' + @new_branch = true + @repository_http_uri = "" + @ssh_key = nil + end + + def remote_branch + @remote_branch ||= branch_name + end + + def directory=(dir) + raise "Must set directory as a Pathname" unless dir.is_a?(Pathname) + + @directory = dir + end + + def files=(files) + if !files.is_a?(Array) || files.empty? + raise ArgumentError, "Please provide an array of hashes e.g.: [{name: 'file1', content: 'foo'}]" + end + + @files = files + end + + def fabricate! + Git::Repository.perform do |repository| + if ssh_key + repository.uri = repository_ssh_uri + repository.use_ssh_key(ssh_key) + else + repository.uri = repository_http_uri + repository.use_default_credentials unless user + end + + username = 'GitLab QA' + email = 'root@gitlab.com' + + if user + repository.username = user.username + repository.password = user.password + username = user.name + email = user.email + end + + repository.clone + repository.configure_identity(username, email) + + if new_branch + repository.checkout_new_branch(branch_name) + else + repository.checkout(branch_name) + end + + if @directory + @directory.each_child do |f| + 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 + repository.add_file(file_name, file_content) + end + + repository.commit(commit_message) + @output = repository.push_changes("#{branch_name}:#{remote_branch}") + + repository.delete_ssh_key + end + end + end + end + end +end diff --git a/qa/qa/resource/repository/wiki_push.rb b/qa/qa/resource/repository/wiki_push.rb new file mode 100644 index 00000000000..f1c39d507fe --- /dev/null +++ b/qa/qa/resource/repository/wiki_push.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module QA + module Resource + module Repository + class WikiPush < Repository::Push + attribute :wiki do + Wiki.fabricate! do |resource| + resource.title = 'Home' + resource.content = '# My First Wiki Content' + resource.message = 'Update home' + end + end + + def initialize + @file_name = 'Home.md' + @file_content = '# Welcome to My Wiki' + @commit_message = 'Updating Home Page' + @branch_name = 'master' + @new_branch = false + end + + def repository_http_uri + @repository_http_uri ||= begin + wiki.visit! + Page::Project::Wiki::Show.act do + go_to_clone_repository + choose_repository_clone_http + repository_location.uri + end + end + end + end + end + end +end |