debian-mirror-gitlab/spec/factories/merge_requests.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

368 lines
10 KiB
Ruby
Raw Normal View History

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