2019-07-25 01:11:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2016-02-16 22:55:24 -05:00
|
|
|
factory :protected_branch do
|
2021-12-01 16:13:44 -05:00
|
|
|
sequence(:name) { |n| "protected_branch_#{n}" }
|
2016-02-16 22:55:24 -05:00
|
|
|
project
|
2016-07-08 02:15:02 -04:00
|
|
|
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
default_push_level { true }
|
|
|
|
default_merge_level { true }
|
|
|
|
default_access_level { true }
|
2016-07-08 02:15:02 -04:00
|
|
|
end
|
|
|
|
|
2021-12-01 16:13:44 -05:00
|
|
|
trait :create_branch_on_repository do
|
|
|
|
association :project, factory: [:project, :repository]
|
|
|
|
|
|
|
|
transient do
|
|
|
|
repository_branch_name { name }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |protected_branch, evaluator|
|
|
|
|
project = protected_branch.project
|
|
|
|
|
|
|
|
project.repository.create_branch(evaluator.repository_branch_name, project.default_branch_or_main)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-08 02:15:02 -04:00
|
|
|
trait :developers_can_push do
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
default_push_level { false }
|
2017-07-27 09:45:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::DEVELOPER)
|
2016-07-29 02:13:07 -04:00
|
|
|
end
|
2016-07-08 02:15:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :developers_can_merge do
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
default_merge_level { false }
|
2017-07-27 09:45:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
|
|
|
protected_branch.merge_access_levels.new(access_level: Gitlab::Access::DEVELOPER)
|
2016-07-29 02:13:07 -04:00
|
|
|
end
|
2016-07-08 02:15:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
trait :no_one_can_push do
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
default_push_level { false }
|
2017-07-27 09:45:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::NO_ACCESS)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
trait :maintainers_can_push do
|
2017-07-27 09:45:17 -04:00
|
|
|
transient do
|
2019-10-01 20:06:26 -04:00
|
|
|
default_push_level { false }
|
2017-07-27 09:45:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
2018-07-11 10:36:08 -04:00
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
|
2017-07-27 09:45:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch, evaluator|
|
|
|
|
if evaluator.default_access_level && evaluator.default_push_level
|
2018-07-11 10:36:08 -04:00
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
|
2017-07-27 09:45:17 -04:00
|
|
|
end
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2017-07-27 09:45:17 -04:00
|
|
|
if evaluator.default_access_level && evaluator.default_merge_level
|
2018-07-11 10:36:08 -04:00
|
|
|
protected_branch.merge_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
|
2016-07-29 02:13:07 -04:00
|
|
|
end
|
2016-07-08 02:15:02 -04:00
|
|
|
end
|
2017-08-02 06:16:17 -04:00
|
|
|
|
|
|
|
trait :no_one_can_merge do
|
|
|
|
after(:create) do |protected_branch|
|
|
|
|
protected_branch.merge_access_levels.first.update!(access_level: Gitlab::Access::NO_ACCESS)
|
|
|
|
end
|
|
|
|
end
|
2016-02-16 22:55:24 -05:00
|
|
|
end
|
|
|
|
end
|