diff options
Diffstat (limited to 'lib/gitlab/github_import/representation/protected_branch.rb')
-rw-r--r-- | lib/gitlab/github_import/representation/protected_branch.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/gitlab/github_import/representation/protected_branch.rb b/lib/gitlab/github_import/representation/protected_branch.rb index d2a52b64bbf..eb9dd3bc247 100644 --- a/lib/gitlab/github_import/representation/protected_branch.rb +++ b/lib/gitlab/github_import/representation/protected_branch.rb @@ -10,7 +10,7 @@ module Gitlab attr_reader :attributes expose_attribute :id, :allow_force_pushes, :required_conversation_resolution, :required_signatures, - :required_pull_request_reviews, :require_code_owner_reviews + :required_pull_request_reviews, :require_code_owner_reviews, :allowed_to_push_users # Builds a Branch Protection info from a GitHub API response. # Resource structure details: @@ -19,6 +19,12 @@ module Gitlab def self.from_api_response(branch_protection, _additional_object_data = {}) branch_name = branch_protection[:url].match(%r{/branches/(\S{1,255})/protection$})[1] + allowed_to_push_users = branch_protection.dig(:required_pull_request_reviews, + :bypass_pull_request_allowances, + :users) + allowed_to_push_users &&= allowed_to_push_users.map do |u| + Representation::User.from_api_response(u) + end hash = { id: branch_name, allow_force_pushes: branch_protection.dig(:allow_force_pushes, :enabled), @@ -26,7 +32,8 @@ module Gitlab required_signatures: branch_protection.dig(:required_signatures, :enabled), required_pull_request_reviews: branch_protection[:required_pull_request_reviews].present?, require_code_owner_reviews: branch_protection.dig(:required_pull_request_reviews, - :require_code_owner_reviews).present? + :require_code_owner_reviews).present?, + allowed_to_push_users: allowed_to_push_users.to_a } new(hash) @@ -34,7 +41,13 @@ module Gitlab # Builds a new Protection using a Hash that was built from a JSON payload. def self.from_json_hash(raw_hash) - new(Representation.symbolize_hash(raw_hash)) + hash = Representation.symbolize_hash(raw_hash) + + hash[:allowed_to_push_users].map! do |u| + Representation::User.from_json_hash(u) + end + + new(hash) end # attributes - A Hash containing the raw Protection details. The keys of this |