2018-11-02 05:32:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'securerandom'
|
|
|
|
|
|
|
|
module QA
|
|
|
|
module Resource
|
|
|
|
class MergeRequest < Base
|
2019-08-29 02:22:58 -04:00
|
|
|
attr_accessor :approval_rules,
|
|
|
|
:id,
|
2019-08-14 04:22:15 -04:00
|
|
|
:title,
|
2018-11-02 05:32:28 -04:00
|
|
|
:description,
|
|
|
|
:source_branch,
|
|
|
|
:target_branch,
|
2019-07-15 13:32:43 -04:00
|
|
|
:target_new_branch,
|
2018-11-02 05:32:28 -04:00
|
|
|
:assignee,
|
|
|
|
:milestone,
|
2018-10-30 14:43:25 -04:00
|
|
|
:labels,
|
|
|
|
:file_name,
|
|
|
|
:file_content
|
2019-09-10 19:20:23 -04:00
|
|
|
attr_writer :no_preparation
|
2018-11-02 05:32:28 -04:00
|
|
|
|
|
|
|
attribute :project do
|
|
|
|
Project.fabricate! do |resource|
|
|
|
|
resource.name = 'project-with-merge-request'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attribute :target do
|
|
|
|
project.visit!
|
|
|
|
|
|
|
|
Repository::ProjectPush.fabricate! do |resource|
|
|
|
|
resource.project = project
|
|
|
|
resource.branch_name = 'master'
|
2019-07-15 13:32:43 -04:00
|
|
|
resource.new_branch = @target_new_branch
|
2018-11-02 05:32:28 -04:00
|
|
|
resource.remote_branch = target_branch
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attribute :source do
|
|
|
|
Repository::ProjectPush.fabricate! do |resource|
|
|
|
|
resource.project = project
|
|
|
|
resource.branch_name = target_branch
|
|
|
|
resource.remote_branch = source_branch
|
|
|
|
resource.new_branch = false
|
2018-10-30 14:43:25 -04:00
|
|
|
resource.file_name = file_name
|
|
|
|
resource.file_content = file_content
|
2018-11-02 05:32:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize
|
2019-08-29 02:22:58 -04:00
|
|
|
@approval_rules = nil
|
2018-11-02 05:32:28 -04:00
|
|
|
@title = 'QA test - merge request'
|
|
|
|
@description = 'This is a test merge request'
|
|
|
|
@source_branch = "qa-test-feature-#{SecureRandom.hex(8)}"
|
|
|
|
@target_branch = "master"
|
|
|
|
@assignee = nil
|
|
|
|
@milestone = nil
|
|
|
|
@labels = []
|
2018-10-30 14:43:25 -04:00
|
|
|
@file_name = "added_file.txt"
|
|
|
|
@file_content = "File Added"
|
2019-07-15 13:32:43 -04:00
|
|
|
@target_new_branch = true
|
2019-09-10 19:20:23 -04:00
|
|
|
@no_preparation = false
|
2018-11-02 05:32:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def fabricate!
|
|
|
|
populate(:target, :source)
|
|
|
|
|
|
|
|
project.visit!
|
2019-02-11 04:04:59 -05:00
|
|
|
Page::Project::Show.perform(&:new_merge_request)
|
2019-08-29 02:22:58 -04:00
|
|
|
Page::MergeRequest::New.perform do |new|
|
|
|
|
new.fill_title(@title)
|
|
|
|
new.fill_description(@description)
|
|
|
|
new.choose_milestone(@milestone) if @milestone
|
|
|
|
new.assign_to_me if @assignee == 'me'
|
2018-11-02 05:32:28 -04:00
|
|
|
labels.each do |label|
|
2019-08-29 02:22:58 -04:00
|
|
|
new.select_label(label)
|
2018-11-02 05:32:28 -04:00
|
|
|
end
|
2019-08-29 02:22:58 -04:00
|
|
|
new.add_approval_rules(approval_rules) if approval_rules
|
2018-11-02 05:32:28 -04:00
|
|
|
|
2019-08-29 02:22:58 -04:00
|
|
|
new.create_merge_request
|
2018-11-02 05:32:28 -04:00
|
|
|
end
|
|
|
|
end
|
2019-08-14 04:22:15 -04:00
|
|
|
|
|
|
|
def fabricate_via_api!
|
2019-09-10 19:20:23 -04:00
|
|
|
populate(:target, :source) unless @no_preparation
|
2019-08-14 04:22:15 -04:00
|
|
|
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
|
2018-11-02 05:32:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|