2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module ProtectedBranches
|
2021-11-11 11:23:49 +05:30
|
|
|
class ApiService < ProtectedBranches::BaseService
|
2018-03-17 18:26:18 +05:30
|
|
|
def create
|
2019-07-07 11:18:12 +05:30
|
|
|
::ProtectedBranches::CreateService.new(@project, @current_user, protected_branch_params).execute
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
def update(protected_branch)
|
|
|
|
::ProtectedBranches::UpdateService.new(@project, @current_user,
|
|
|
|
protected_branch_params(with_defaults: false)).execute(protected_branch)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
2023-01-13 00:05:48 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def protected_branch_params(with_defaults: true)
|
|
|
|
params.slice(*attributes).merge(
|
|
|
|
{
|
|
|
|
push_access_levels_attributes: access_level_attributes(:push, with_defaults),
|
|
|
|
merge_access_levels_attributes: access_level_attributes(:merge, with_defaults)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def access_level_attributes(type, with_defaults)
|
|
|
|
::ProtectedRefs::AccessLevelParams.new(
|
|
|
|
type,
|
|
|
|
params,
|
|
|
|
with_defaults: with_defaults
|
|
|
|
).access_levels
|
|
|
|
end
|
|
|
|
|
|
|
|
def attributes
|
|
|
|
[:name, :allow_force_push]
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
ProtectedBranches::ApiService.prepend_mod_with('ProtectedBranches::ApiService')
|