2018-07-18 16:03:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-22 17:08:47 +00:00
|
|
|
module ProtectedBranches
|
2021-09-07 15:11:06 +00:00
|
|
|
class ApiService < ProtectedBranches::BaseService
|
2017-11-22 17:08:47 +00:00
|
|
|
def create
|
2019-02-06 12:41:17 +00:00
|
|
|
::ProtectedBranches::CreateService.new(@project, @current_user, protected_branch_params).execute
|
|
|
|
end
|
2017-11-22 17:08:47 +00:00
|
|
|
|
2019-02-06 12:41:17 +00:00
|
|
|
def protected_branch_params
|
|
|
|
{
|
2017-11-22 17:08:47 +00:00
|
|
|
name: params[:name],
|
2021-03-11 18:09:23 +00:00
|
|
|
allow_force_push: allow_force_push?,
|
2022-07-13 21:10:15 +00:00
|
|
|
push_access_levels_attributes: ::ProtectedRefs::AccessLevelParams.new(:push, params).access_levels,
|
|
|
|
merge_access_levels_attributes: ::ProtectedRefs::AccessLevelParams.new(:merge, params).access_levels
|
2017-11-22 17:08:47 +00:00
|
|
|
}
|
|
|
|
end
|
2021-03-11 18:09:23 +00:00
|
|
|
|
|
|
|
def allow_force_push?
|
|
|
|
params[:allow_force_push] || false
|
|
|
|
end
|
2017-11-22 17:08:47 +00:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
ProtectedBranches::ApiService.prepend_mod_with('ProtectedBranches::ApiService')
|