Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qa/resource/merge_request.rb')
-rw-r--r--qa/qa/resource/merge_request.rb71
1 files changed, 45 insertions, 26 deletions
diff --git a/qa/qa/resource/merge_request.rb b/qa/qa/resource/merge_request.rb
index ba63e0823f0..685cccea02d 100644
--- a/qa/qa/resource/merge_request.rb
+++ b/qa/qa/resource/merge_request.rb
@@ -6,11 +6,13 @@ module QA
attr_accessor :approval_rules,
:source_branch,
:target_new_branch,
+ :update_existing_file,
:assignee,
:milestone,
:labels,
:file_name,
:file_content
+
attr_writer :no_preparation,
:wait_for_merge,
:template
@@ -25,6 +27,8 @@ module QA
attribute :project do
Project.fabricate_via_api! do |resource|
resource.name = 'project-with-merge-request'
+ resource.initialize_with_readme = true
+ resource.api_client = api_client
end
end
@@ -33,22 +37,27 @@ module QA
end
attribute :target do
- Repository::ProjectPush.fabricate! do |resource|
+ Repository::Commit.fabricate_via_api! do |resource|
resource.project = project
- resource.branch_name = target_branch
- resource.new_branch = target_new_branch
- resource.remote_branch = target_branch
+ resource.api_client = api_client
+ resource.commit_message = 'This is a test commit'
+ resource.add_files([{ 'file_path': "file-#{SecureRandom.hex(8)}.txt", 'content': 'MR init' }])
+ resource.branch = target_branch
+
+ resource.start_branch = project.default_branch if target_branch != project.default_branch
end
end
attribute :source do
- Repository::ProjectPush.fabricate! do |resource|
+ Repository::Commit.fabricate_via_api! do |resource|
resource.project = project
- resource.branch_name = target_branch
- resource.remote_branch = source_branch
- resource.new_branch = false
- resource.file_name = file_name
- resource.file_content = file_content
+ resource.api_client = api_client
+ resource.commit_message = 'This is a test commit'
+ resource.branch = source_branch
+ resource.start_branch = target_branch
+
+ files = [{ 'file_path': file_name, 'content': file_content }]
+ update_existing_file ? resource.update_files(files) : resource.add_files(files)
end
end
@@ -63,6 +72,7 @@ module QA
@file_name = "added_file-#{SecureRandom.hex(8)}.txt"
@file_content = "File Added"
@target_new_branch = true
+ @update_existing_file = false
@no_preparation = false
@wait_for_merge = true
end
@@ -168,27 +178,18 @@ module QA
)
end
- # Object comparison
- #
- # @param [QA::Resource::MergeRequest] other
- # @return [Boolean]
- def ==(other)
- other.is_a?(MergeRequest) && comparable_mr == other.comparable_mr
- end
-
- # Override inspect for a better rspec failure diff output
+ # Add mr comment
#
- # @return [String]
- def inspect
- JSON.pretty_generate(comparable_mr)
+ # @param [String] body
+ # @return [Hash]
+ def add_comment(body)
+ api_post_to(api_comments_path, body: body)
end
- protected
-
# Return subset of fields for comparing merge requests
#
# @return [Hash]
- def comparable_mr
+ def comparable
reload! if api_response.nil?
api_resource.except(
@@ -197,7 +198,9 @@ module QA
:project_id,
:source_project_id,
:target_project_id,
+ :merge_status,
# these can differ depending on user fetching mr
+ :user,
:subscribed,
:first_contribution
).merge({ references: api_resource[:references].except(:full) })
@@ -211,8 +214,24 @@ module QA
super(api_resource)
end
+ # Create source and target and commits if necessary
+ #
+ # @return [void]
def populate_target_and_source_if_required
- populate(:target, :source) unless @no_preparation
+ return if @no_preparation
+
+ populate(:target) if create_target?
+ populate(:source)
+ end
+
+ # Check if target needs to be created
+ #
+ # Return false if project was already initialized and mr target is default branch
+ # Return false if target_new_branch is explicitly set to false
+ #
+ # @return [Boolean]
+ def create_target?
+ !(project.initialize_with_readme && target_branch == project.default_branch) && target_new_branch
end
end
end