diff options
author | Tomislav Nikic <tnikic@gitlab.com> | 2019-08-01 11:57:15 +0200 |
---|---|---|
committer | Tomislav Nikic <tnikic@gitlab.com> | 2019-08-01 11:57:15 +0200 |
commit | 6d9670d2e1789d573734941e082476366d38a58f (patch) | |
tree | 8a8fae07ed440eb0212eae1978aa824c47be1271 | |
parent | 4072c8e1bc6a0dc738a1419379be73fd51fb27f4 (diff) | |
download | gitlab-ce-6d9670d2e1789d573734941e082476366d38a58f.tar.gz |
Adding API capabilities
Adding the ability to create resources (push and merge_request) using
the API.
-rw-r--r-- | qa/qa/resource/merge_request.rb | 31 | ||||
-rw-r--r-- | qa/qa/resource/repository/project_push.rb | 31 |
2 files changed, 57 insertions, 5 deletions
diff --git a/qa/qa/resource/merge_request.rb b/qa/qa/resource/merge_request.rb index 7969de726e4..dd0b4c42b11 100644 --- a/qa/qa/resource/merge_request.rb +++ b/qa/qa/resource/merge_request.rb @@ -5,7 +5,8 @@ require 'securerandom' module QA module Resource class MergeRequest < Base - attr_accessor :title, + attr_accessor :id, + :title, :description, :source_branch, :target_branch, @@ -25,16 +26,16 @@ module QA attribute :target do project.visit! - Repository::ProjectPush.fabricate! do |resource| + Repository::ProjectPush.fabricate_via_api! do |resource| resource.project = project - resource.branch_name = 'master' + resource.branch_name = target_branch resource.new_branch = @target_new_branch resource.remote_branch = target_branch end end attribute :source do - Repository::ProjectPush.fabricate! do |resource| + Repository::ProjectPush.fabricate_via_api! do |resource| resource.project = project resource.branch_name = target_branch resource.remote_branch = source_branch @@ -74,6 +75,28 @@ module QA page.create_merge_request end end + + def fabricate_via_api! + populate(:target, :source) + super + end + + def api_get_path + "/projects/#{project.id}/merge_requests/#{id}" + end + + def api_post_path + "/projects/#{project.id}/merge_requests" + end + + def api_post_body + { + description: @description, + source_branch: @source_branch, + target_branch: @target_branch, + title: @title + } + end end end end diff --git a/qa/qa/resource/repository/project_push.rb b/qa/qa/resource/repository/project_push.rb index e98880ce195..9bf0e51ad58 100644 --- a/qa/qa/resource/repository/project_push.rb +++ b/qa/qa/resource/repository/project_push.rb @@ -7,7 +7,7 @@ module QA attr_writer :wait_for_push attribute :project do - Project.fabricate! do |resource| + Project.fabricate_via_api! do |resource| resource.name = 'project-with-code' resource.description = 'Project with repository' end @@ -35,6 +35,35 @@ module QA project.wait_for_push @commit_message if @wait_for_push project.visit! end + + 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/commits" + end + + def api_post_path + "/projects/#{project.id}/repository/commits" + end + + def api_post_body + { + branch: @remote_branch, + start_branch: @branch_name, + commit_message: @commit_message, + actions: [ + { + action: "create", + file_path: @file_name, + content: @file_content + } + ] + } + end end end end |