2016-07-07 10:48:07 +00:00
|
|
|
module ProtectedBranches
|
2016-07-08 09:15:29 +00:00
|
|
|
class CreateService < ProtectedBranches::BaseService
|
2016-07-07 10:48:07 +00:00
|
|
|
attr_reader :protected_branch
|
2016-07-07 07:36:28 +00:00
|
|
|
|
2016-07-07 10:48:07 +00:00
|
|
|
def execute
|
|
|
|
ProtectedBranch.transaction do
|
|
|
|
@protected_branch = project.protected_branches.new(name: params[:name])
|
|
|
|
@protected_branch.save!
|
2016-07-07 07:36:28 +00:00
|
|
|
|
2016-07-07 10:48:07 +00:00
|
|
|
@protected_branch.create_push_access_level!
|
|
|
|
@protected_branch.create_merge_access_level!
|
2016-07-07 07:36:28 +00:00
|
|
|
|
2016-07-07 10:48:07 +00:00
|
|
|
set_access_levels!
|
|
|
|
end
|
2016-07-07 07:36:28 +00:00
|
|
|
|
2016-07-07 10:48:07 +00:00
|
|
|
true
|
|
|
|
rescue ActiveRecord::RecordInvalid
|
|
|
|
false
|
|
|
|
end
|
2016-07-07 07:36:28 +00:00
|
|
|
end
|
|
|
|
end
|