2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
FactoryBot.define do
|
2016-06-02 11:05:42 +05:30
|
|
|
factory :protected_branch do
|
2022-01-26 12:08:38 +05:30
|
|
|
sequence(:name) { |n| "protected_branch_#{n}" }
|
2016-06-02 11:05:42 +05:30
|
|
|
project
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
transient do
|
2022-10-11 01:57:18 +05:30
|
|
|
ee { false }
|
2019-12-21 20:55:43 +05:30
|
|
|
default_push_level { true }
|
|
|
|
default_merge_level { true }
|
|
|
|
default_access_level { true }
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
after(:create) do |protected_branch, evaluator|
|
|
|
|
break unless protected_branch.project&.persisted?
|
|
|
|
|
|
|
|
ProtectedBranches::CacheService.new(protected_branch.project).refresh
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |obj, ctx|
|
|
|
|
next if ctx.ee || !ctx.default_access_level
|
|
|
|
|
|
|
|
obj.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER) if ctx.default_push_level
|
|
|
|
obj.merge_access_levels.new(access_level: Gitlab::Access::MAINTAINER) if ctx.default_merge_level
|
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
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
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
trait :maintainers_can_push do
|
2017-09-10 17:25:29 +05:30
|
|
|
transient do
|
2019-12-21 20:55:43 +05:30
|
|
|
default_push_level { false }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
2022-10-11 01:57:18 +05:30
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
trait :maintainers_can_merge do
|
2017-09-10 17:25:29 +05:30
|
|
|
transient do
|
2022-10-11 01:57:18 +05:30
|
|
|
default_push_level { false }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
2022-10-11 01:57:18 +05:30
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::MAINTAINER)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
trait :developers_can_push do
|
2017-09-10 17:25:29 +05:30
|
|
|
transient do
|
2019-12-21 20:55:43 +05:30
|
|
|
default_push_level { false }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
2022-10-11 01:57:18 +05:30
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::DEVELOPER)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
trait :developers_can_merge do
|
2017-09-10 17:25:29 +05:30
|
|
|
transient do
|
2022-10-11 01:57:18 +05:30
|
|
|
default_merge_level { false }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
2022-10-11 01:57:18 +05:30
|
|
|
protected_branch.merge_access_levels.new(access_level: Gitlab::Access::DEVELOPER)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
trait :no_one_can_push do
|
|
|
|
transient do
|
|
|
|
default_push_level { false }
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
after(:build) do |protected_branch|
|
|
|
|
protected_branch.push_access_levels.new(access_level: Gitlab::Access::NO_ACCESS)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :no_one_can_merge do
|
2022-10-11 01:57:18 +05:30
|
|
|
transient do
|
|
|
|
default_merge_level { false }
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |protected_branch|
|
|
|
|
protected_branch.merge_access_levels.new(access_level: Gitlab::Access::NO_ACCESS)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|