Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_service.rb « protected_branches « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3601990641628416b75fefa8dc94dc077b4773d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module ProtectedBranches
  class CreateService < ProtectedBranches::BaseService
    attr_reader :protected_branch

    def execute
      raise Gitlab::Access::AccessDeniedError unless current_user.can?(:admin_project, project)

      ProtectedBranch.transaction do
        @protected_branch = project.protected_branches.new(name: params[:name])
        @protected_branch.save!

        @protected_branch.create_push_access_level!
        @protected_branch.create_merge_access_level!

        set_access_levels!
      end

      true
    rescue ActiveRecord::RecordInvalid
      false
    end
  end
end