2019-07-25 05:11:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-14 00:13:44 +00:00
|
|
|
FactoryBot.define do
|
2020-04-03 18:10:03 +00:00
|
|
|
factory :merge_request, traits: [:has_internal_id] do
|
2017-03-23 16:37:14 +00:00
|
|
|
title { generate(:title) }
|
2017-01-25 19:52:12 +00:00
|
|
|
association :source_project, :repository, factory: :project
|
2014-07-31 15:07:24 +00:00
|
|
|
target_project { source_project }
|
2017-08-04 17:14:04 +00:00
|
|
|
author { source_project.creator }
|
2014-07-31 15:07:24 +00:00
|
|
|
|
2015-06-22 18:43:51 +00:00
|
|
|
# $ git log --pretty=oneline feature..master
|
2014-07-31 15:07:24 +00:00
|
|
|
# 5937ac0a7beb003549fc5fd26fc247adbce4a52e Add submodule from gitlab.com
|
|
|
|
# 570e7b2abdd848b95f2f578043fc23bd6f6fd24d Change some files
|
|
|
|
# 6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9 More submodules
|
|
|
|
# d14d6c0abdd253381df51a723d58691b2ee1ab08 Remove ds_store files
|
|
|
|
# c1acaa58bbcbc3eafe538cb8274ba387047b69f8 Ignore DS files
|
2014-08-06 06:52:56 +00:00
|
|
|
#
|
|
|
|
# See also RepoHelpers.sample_compare
|
|
|
|
#
|
2019-10-02 00:06:26 +00:00
|
|
|
source_branch { "master" }
|
|
|
|
target_branch { "feature" }
|
2014-07-31 15:07:24 +00:00
|
|
|
|
2019-10-02 00:06:26 +00:00
|
|
|
merge_status { "can_be_merged" }
|
2014-07-31 15:07:24 +00:00
|
|
|
|
|
|
|
trait :with_diffs do
|
|
|
|
end
|
|
|
|
|
2017-10-07 04:25:17 +00:00
|
|
|
trait :with_image_diffs do
|
2019-10-02 00:06:26 +00:00
|
|
|
source_branch { "add_images_and_changes" }
|
|
|
|
target_branch { "master" }
|
2017-10-07 04:25:17 +00:00
|
|
|
end
|
|
|
|
|
2016-03-09 07:19:54 +00:00
|
|
|
trait :without_diffs do
|
2019-10-02 00:06:26 +00:00
|
|
|
source_branch { "improve/awesome" }
|
|
|
|
target_branch { "master" }
|
2016-03-09 07:19:54 +00:00
|
|
|
end
|
|
|
|
|
2014-08-06 06:52:56 +00:00
|
|
|
trait :conflict do
|
2019-10-02 00:06:26 +00:00
|
|
|
source_branch { "feature_conflict" }
|
|
|
|
target_branch { "feature" }
|
2014-08-06 06:52:56 +00:00
|
|
|
end
|
|
|
|
|
2016-03-01 11:32:20 +00:00
|
|
|
trait :merged do
|
2019-10-18 11:11:44 +00:00
|
|
|
state_id { MergeRequest.available_states[:merged] }
|
2016-03-01 11:32:20 +00:00
|
|
|
end
|
|
|
|
|
2020-08-13 18:10:36 +00:00
|
|
|
trait :with_merged_metrics do
|
|
|
|
merged
|
|
|
|
|
|
|
|
transient do
|
|
|
|
merged_by { author }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |merge_request, evaluator|
|
|
|
|
metrics = merge_request.build_metrics
|
|
|
|
metrics.merged_at = 1.week.ago
|
|
|
|
metrics.merged_by = evaluator.merged_by
|
|
|
|
metrics.pipeline = create(:ci_empty_pipeline)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-08 21:44:32 +00:00
|
|
|
trait :merged_target do
|
2019-10-02 00:06:26 +00:00
|
|
|
source_branch { "merged-target" }
|
|
|
|
target_branch { "improve/awesome" }
|
2018-05-08 21:44:32 +00:00
|
|
|
end
|
|
|
|
|
2019-02-20 15:35:57 +00:00
|
|
|
trait :merged_last_month do
|
|
|
|
merged
|
|
|
|
|
|
|
|
after(:build) do |merge_request|
|
|
|
|
merge_request.build_metrics.merged_at = 1.month.ago
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-31 15:07:24 +00:00
|
|
|
trait :closed do
|
2019-10-18 11:11:44 +00:00
|
|
|
state_id { MergeRequest.available_states[:closed] }
|
2014-07-31 15:07:24 +00:00
|
|
|
end
|
|
|
|
|
2019-02-20 15:35:57 +00:00
|
|
|
trait :closed_last_month do
|
|
|
|
closed
|
|
|
|
|
|
|
|
after(:build) do |merge_request|
|
|
|
|
merge_request.build_metrics.latest_closed_at = 1.month.ago
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-17 03:51:16 +00:00
|
|
|
trait :opened do
|
2019-10-18 11:11:44 +00:00
|
|
|
state_id { MergeRequest.available_states[:opened] }
|
2017-04-17 03:51:16 +00:00
|
|
|
end
|
|
|
|
|
2018-06-05 11:42:18 +00:00
|
|
|
trait :invalid do
|
2019-10-02 00:06:26 +00:00
|
|
|
source_branch { "feature_one" }
|
|
|
|
target_branch { "feature_two" }
|
2018-06-05 11:42:18 +00:00
|
|
|
end
|
|
|
|
|
2016-08-24 17:11:48 +00:00
|
|
|
trait :locked do
|
2019-10-18 11:11:44 +00:00
|
|
|
state_id { MergeRequest.available_states[:locked] }
|
2016-08-24 17:11:48 +00:00
|
|
|
end
|
|
|
|
|
2014-07-31 15:07:24 +00:00
|
|
|
trait :simple do
|
2019-10-02 00:06:26 +00:00
|
|
|
source_branch { "feature" }
|
|
|
|
target_branch { "master" }
|
2014-07-31 15:07:24 +00:00
|
|
|
end
|
|
|
|
|
2016-02-04 18:23:58 +00:00
|
|
|
trait :rebased do
|
2019-10-02 00:06:26 +00:00
|
|
|
source_branch { "markdown" }
|
|
|
|
target_branch { "improve/awesome" }
|
2016-02-04 18:23:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :diverged do
|
2019-10-02 00:06:26 +00:00
|
|
|
source_branch { "feature" }
|
|
|
|
target_branch { "master" }
|
2016-02-04 18:23:58 +00:00
|
|
|
end
|
|
|
|
|
2017-02-17 13:56:13 +00:00
|
|
|
trait :merge_when_pipeline_succeeds do
|
2019-10-02 00:06:26 +00:00
|
|
|
auto_merge_enabled { true }
|
|
|
|
auto_merge_strategy { AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS }
|
2018-09-20 17:02:36 +00:00
|
|
|
merge_user { author }
|
2019-11-15 15:06:12 +00:00
|
|
|
merge_params { { sha: diff_head_sha } }
|
2015-12-03 09:27:34 +00:00
|
|
|
end
|
|
|
|
|
2017-10-11 20:06:15 +00:00
|
|
|
trait :remove_source_branch do
|
|
|
|
merge_params do
|
|
|
|
{ 'force_remove_source_branch' => '1' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-05 21:08:27 +00:00
|
|
|
trait :with_head_pipeline do
|
|
|
|
after(:build) do |merge_request|
|
|
|
|
merge_request.head_pipeline = build(
|
|
|
|
:ci_pipeline,
|
|
|
|
:running,
|
|
|
|
project: merge_request.source_project,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-02 06:05:07 +00:00
|
|
|
trait :with_test_reports do
|
2018-08-03 11:08:13 +00:00
|
|
|
after(:build) do |merge_request|
|
|
|
|
merge_request.head_pipeline = build(
|
|
|
|
:ci_pipeline,
|
2018-08-02 06:05:07 +00:00
|
|
|
:success,
|
2018-08-03 12:53:29 +00:00
|
|
|
:with_test_reports,
|
2018-08-02 06:05:07 +00:00
|
|
|
project: merge_request.source_project,
|
|
|
|
ref: merge_request.source_branch,
|
2018-08-03 11:08:13 +00:00
|
|
|
sha: merge_request.diff_head_sha)
|
2018-08-02 06:05:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-08 21:09:47 +00:00
|
|
|
trait :with_accessibility_reports do
|
|
|
|
after(:build) do |merge_request|
|
|
|
|
merge_request.head_pipeline = build(
|
|
|
|
:ci_pipeline,
|
|
|
|
:success,
|
|
|
|
:with_accessibility_reports,
|
|
|
|
project: merge_request.source_project,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-22 00:08:07 +00:00
|
|
|
trait :unique_branches do
|
|
|
|
source_branch { generate(:branch) }
|
|
|
|
target_branch { generate(:branch) }
|
|
|
|
end
|
|
|
|
|
2020-10-05 18:08:51 +00:00
|
|
|
trait :unique_author do
|
|
|
|
author { association(:user) }
|
|
|
|
end
|
|
|
|
|
2020-03-17 18:09:44 +00:00
|
|
|
trait :with_coverage_reports do
|
|
|
|
after(:build) do |merge_request|
|
|
|
|
merge_request.head_pipeline = build(
|
|
|
|
:ci_pipeline,
|
|
|
|
:success,
|
2020-08-25 12:04:30 +00:00
|
|
|
:with_coverage_report_artifact,
|
2020-03-17 18:09:44 +00:00
|
|
|
project: merge_request.source_project,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
trait :with_terraform_reports do
|
|
|
|
after(:build) do |merge_request|
|
|
|
|
merge_request.head_pipeline = build(
|
|
|
|
:ci_pipeline,
|
|
|
|
:success,
|
|
|
|
:with_terraform_reports,
|
|
|
|
project: merge_request.source_project,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-21 15:05:58 +00:00
|
|
|
trait :with_exposed_artifacts do
|
|
|
|
after(:build) do |merge_request|
|
|
|
|
merge_request.head_pipeline = build(
|
|
|
|
:ci_pipeline,
|
|
|
|
:success,
|
|
|
|
:with_exposed_artifacts,
|
|
|
|
project: merge_request.source_project,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-21 13:08:32 +00:00
|
|
|
trait :with_legacy_detached_merge_request_pipeline do
|
|
|
|
after(:create) do |merge_request|
|
2020-03-30 18:08:07 +00:00
|
|
|
create(:ci_pipeline, :legacy_detached_merge_request_pipeline, merge_request: merge_request)
|
2019-03-21 13:08:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-07 07:33:13 +00:00
|
|
|
trait :with_detached_merge_request_pipeline do
|
2019-03-21 13:08:32 +00:00
|
|
|
after(:create) do |merge_request|
|
2020-03-30 18:08:07 +00:00
|
|
|
create(:ci_pipeline, :detached_merge_request_pipeline, merge_request: merge_request)
|
2019-02-28 09:15:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-07 07:33:13 +00:00
|
|
|
trait :with_merge_request_pipeline do
|
|
|
|
transient do
|
|
|
|
merge_sha { 'test-merge-sha' }
|
|
|
|
source_sha { source_branch_sha }
|
|
|
|
target_sha { target_branch_sha }
|
|
|
|
end
|
|
|
|
|
2019-03-21 13:08:32 +00:00
|
|
|
after(:create) do |merge_request, evaluator|
|
2020-03-30 18:08:07 +00:00
|
|
|
create(:ci_pipeline, :merged_result_pipeline,
|
2019-03-07 07:33:13 +00:00
|
|
|
merge_request: merge_request,
|
|
|
|
sha: evaluator.merge_sha,
|
|
|
|
source_sha: evaluator.source_sha,
|
2020-03-30 18:08:07 +00:00
|
|
|
target_sha: evaluator.target_sha
|
|
|
|
)
|
2019-03-07 07:33:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-09 16:17:40 +00:00
|
|
|
trait :deployed_review_app do
|
2019-10-02 00:06:26 +00:00
|
|
|
target_branch { 'pages-deploy-target' }
|
2018-10-09 16:17:40 +00:00
|
|
|
|
|
|
|
transient do
|
|
|
|
deployment { create(:deployment, :review_app) }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |merge_request, evaluator|
|
|
|
|
merge_request.source_branch = evaluator.deployment.ref
|
|
|
|
merge_request.source_project = evaluator.deployment.project
|
|
|
|
merge_request.target_project = evaluator.deployment.project
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-17 09:07:48 +00:00
|
|
|
trait :sequence_source_branch do
|
|
|
|
sequence(:source_branch) { |n| "feature#{n}" }
|
|
|
|
end
|
|
|
|
|
2017-08-09 11:30:07 +00:00
|
|
|
after(:build) do |merge_request|
|
|
|
|
target_project = merge_request.target_project
|
2017-08-09 13:41:45 +00:00
|
|
|
source_project = merge_request.source_project
|
2017-08-09 11:30:07 +00:00
|
|
|
|
2017-11-06 14:03:11 +00:00
|
|
|
# Fake `fetch_ref!` if we don't have repository
|
2017-08-09 11:30:07 +00:00
|
|
|
# We have too many existing tests replying on this behaviour
|
2017-08-09 13:41:45 +00:00
|
|
|
unless [target_project, source_project].all?(&:repository_exists?)
|
2017-11-06 14:03:11 +00:00
|
|
|
allow(merge_request).to receive(:fetch_ref!)
|
2017-08-09 11:30:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-18 11:11:44 +00:00
|
|
|
after(:build) do |merge_request, evaluator|
|
|
|
|
merge_request.state_id = MergeRequest.available_states[evaluator.state]
|
|
|
|
end
|
|
|
|
|
2018-07-30 18:52:42 +00:00
|
|
|
after(:create) do |merge_request, evaluator|
|
|
|
|
merge_request.cache_merge_request_closes_issues!
|
|
|
|
end
|
|
|
|
|
2016-03-01 11:32:20 +00:00
|
|
|
factory :merged_merge_request, traits: [:merged]
|
2014-07-31 15:07:24 +00:00
|
|
|
factory :closed_merge_request, traits: [:closed]
|
2017-07-19 14:03:50 +00:00
|
|
|
factory :reopened_merge_request, traits: [:opened]
|
2018-06-05 11:42:18 +00:00
|
|
|
factory :invalid_merge_request, traits: [:invalid]
|
2014-07-31 15:07:24 +00:00
|
|
|
factory :merge_request_with_diffs, traits: [:with_diffs]
|
2016-09-16 11:02:42 +00:00
|
|
|
factory :merge_request_with_diff_notes do
|
|
|
|
after(:create) do |mr|
|
|
|
|
create(:diff_note_on_merge_request, noteable: mr, project: mr.source_project)
|
|
|
|
end
|
|
|
|
end
|
2016-09-26 20:10:54 +00:00
|
|
|
|
|
|
|
factory :labeled_merge_request do
|
|
|
|
transient do
|
2019-10-02 00:06:26 +00:00
|
|
|
labels { [] }
|
2016-09-26 20:10:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |merge_request, evaluator|
|
2020-07-21 12:09:30 +00:00
|
|
|
merge_request.update!(labels: evaluator.labels)
|
2016-09-26 20:10:54 +00:00
|
|
|
end
|
|
|
|
end
|
2020-09-28 18:09:40 +00:00
|
|
|
|
|
|
|
factory :merge_request_without_merge_request_diff, class: 'MergeRequestWithoutMergeRequestDiff'
|
2014-07-31 15:07:24 +00:00
|
|
|
end
|
|
|
|
end
|