summaryrefslogtreecommitdiff
path: root/qa/qa/resource/repository
diff options
context:
space:
mode:
authorMark Lapierre <mlapierre@gitlab.com>2019-08-12 15:03:10 +1000
committerMark Lapierre <mlapierre@gitlab.com>2019-08-29 13:07:43 +1000
commit7a2bc31e38892f2d064b75710e37d6b3a31a3a03 (patch)
tree92ea1a00e145b4bdf0f8a636cd692ea3f0a82b50 /qa/qa/resource/repository
parentda573ae259f132e8a557001f54d58037f2534753 (diff)
downloadgitlab-ce-7a2bc31e38892f2d064b75710e37d6b3a31a3a03.tar.gz
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/8186
Diffstat (limited to 'qa/qa/resource/repository')
-rw-r--r--qa/qa/resource/repository/commit.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/qa/qa/resource/repository/commit.rb b/qa/qa/resource/repository/commit.rb
new file mode 100644
index 00000000000..61c2ad6bfc0
--- /dev/null
+++ b/qa/qa/resource/repository/commit.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+module QA
+ module Resource
+ module Repository
+ class Commit < Base
+ attr_accessor :author_email,
+ :author_name,
+ :branch,
+ :commit_message,
+ :file_path,
+ :sha
+
+ attribute :project do
+ Project.fabricate! do |resource|
+ resource.name = 'project-with-commit'
+ end
+ end
+
+ def initialize
+ @commit_message = 'QA Test - Commit message'
+ end
+
+ def files=(files)
+ if !files.is_a?(Array) ||
+ files.empty? ||
+ files.any? { |file| !file.has_key?(:file_path) || !file.has_key?(:content) }
+ raise ArgumentError, "Please provide an array of hashes e.g.: [{file_path: 'file1', content: 'foo'}]"
+ end
+
+ @files = files
+ end
+
+ def resource_web_url(resource)
+ super
+ rescue ResourceURLMissingError
+ # this particular resource does not expose a web_url property
+ end
+
+ def api_get_path
+ "#{api_post_path}/#{@sha}"
+ end
+
+ def api_post_path
+ "/projects/#{CGI.escape(project.path_with_namespace)}/repository/commits"
+ end
+
+ def api_post_body
+ {
+ branch: @branch || "master",
+ author_email: @author_email || Runtime::User.default_email,
+ author_name: @author_name || Runtime::User.username,
+ commit_message: commit_message,
+ actions: actions
+ }
+ end
+
+ def actions
+ @files.map do |file|
+ file.merge({ action: "create" })
+ end
+ end
+ end
+ end
+ end
+end