summaryrefslogtreecommitdiff
path: root/app/services/protected_branches/api_service.rb
blob: f604a57bcd1d49c066b342dd90b22a5e4aadf5a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

module ProtectedBranches
  class ApiService < ProtectedBranches::BaseService
    def create
      ::ProtectedBranches::CreateService.new(@project, @current_user, protected_branch_params).execute
    end

    def protected_branch_params
      {
        name: params[:name],
        allow_force_push: allow_force_push?,
        push_access_levels_attributes: ::ProtectedRefs::AccessLevelParams.new(:push, params).access_levels,
        merge_access_levels_attributes: ::ProtectedRefs::AccessLevelParams.new(:merge, params).access_levels
      }
    end

    def allow_force_push?
      params[:allow_force_push] || false
    end
  end
end

ProtectedBranches::ApiService.prepend_mod_with('ProtectedBranches::ApiService')