diff options
Diffstat (limited to 'lib/gitlab/github_import/representation/pull_request_review.rb')
-rw-r--r-- | lib/gitlab/github_import/representation/pull_request_review.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/gitlab/github_import/representation/pull_request_review.rb b/lib/gitlab/github_import/representation/pull_request_review.rb new file mode 100644 index 00000000000..3205259a1ed --- /dev/null +++ b/lib/gitlab/github_import/representation/pull_request_review.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Gitlab + module GithubImport + module Representation + class PullRequestReview + include ToHash + include ExposeAttribute + + attr_reader :attributes + + expose_attribute :author, :note, :review_type, :submitted_at, :github_id, :merge_request_id + + def self.from_api_response(review) + user = Representation::User.from_api_response(review.user) if review.user + + new( + merge_request_id: review.merge_request_id, + author: user, + note: review.body, + review_type: review.state, + submitted_at: review.submitted_at, + github_id: review.id + ) + end + + # Builds a new note using a Hash that was built from a JSON payload. + def self.from_json_hash(raw_hash) + hash = Representation.symbolize_hash(raw_hash) + + hash[:author] &&= Representation::User.from_json_hash(hash[:author]) + hash[:submitted_at] = Time.parse(hash[:submitted_at]).in_time_zone + + new(hash) + end + + # attributes - A Hash containing the raw note details. The keys of this + # Hash must be Symbols. + def initialize(attributes) + @attributes = attributes + end + + def approval? + review_type == 'APPROVED' + end + end + end + end +end |