Welcome to mirror list, hosted at ThFree Co, Russian Federation.

review_requests.rb « pull_requests « representation « github_import « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a3ca5cb644ded529ba8d5a6a2fd620f7f9dd7b7a (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

module Gitlab
  module GithubImport
    module Representation
      module PullRequests
        class ReviewRequests
          include Representable

          expose_attribute :merge_request_id, :merge_request_iid, :users

          class << self
            # Builds a list of requested reviewers from a GitHub API response.
            #
            # review_requests - An instance of `Hash` containing the review requests details.
            def from_api_response(review_requests, _additional_data = {})
              review_requests = Representation.symbolize_hash(review_requests)
              users = review_requests[:users].map do |user_data|
                Representation::User.from_api_response(user_data)
              end

              new(
                merge_request_id: review_requests[:merge_request_id],
                merge_request_iid: review_requests[:merge_request_iid],
                users: users
              )
            end
            alias_method :from_json_hash, :from_api_response
          end

          # attributes - A Hash containing the review details. The keys of this
          #              Hash (and any nested hashes) must be symbols.
          def initialize(attributes)
            @attributes = attributes
          end

          def github_identifiers
            {
              merge_request_iid: merge_request_iid,
              requested_reviewers: users.pluck(:login) # rubocop: disable CodeReuse/ActiveRecord
            }
          end
        end
      end
    end
  end
end