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