diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /lib/gitlab/github_import/representation | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'lib/gitlab/github_import/representation')
-rw-r--r-- | lib/gitlab/github_import/representation/pull_request.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/github_import/representation/pull_request_review.rb | 49 |
2 files changed, 57 insertions, 9 deletions
diff --git a/lib/gitlab/github_import/representation/pull_request.rb b/lib/gitlab/github_import/representation/pull_request.rb index 0ccc4bfaed3..be192762e05 100644 --- a/lib/gitlab/github_import/representation/pull_request.rb +++ b/lib/gitlab/github_import/representation/pull_request.rb @@ -13,18 +13,16 @@ module Gitlab :source_branch_sha, :target_branch, :target_branch_sha, :milestone_number, :author, :assignee, :created_at, :updated_at, :merged_at, :source_repository_id, - :target_repository_id, :source_repository_owner + :target_repository_id, :source_repository_owner, :merged_by # Builds a PR from a GitHub API response. # # issue - An instance of `Sawyer::Resource` containing the PR details. def self.from_api_response(pr) - assignee = - if pr.assignee - Representation::User.from_api_response(pr.assignee) - end - + assignee = Representation::User.from_api_response(pr.assignee) if pr.assignee user = Representation::User.from_api_response(pr.user) if pr.user + merged_by = Representation::User.from_api_response(pr.merged_by) if pr.merged_by + hash = { iid: pr.number, title: pr.title, @@ -42,7 +40,8 @@ module Gitlab assignee: assignee, created_at: pr.created_at, updated_at: pr.updated_at, - merged_at: pr.merged_at + merged_at: pr.merged_at, + merged_by: merged_by } new(hash) @@ -57,8 +56,8 @@ module Gitlab # Assignees are optional so we only convert it from a Hash if one was # set. - hash[:assignee] &&= Representation::User - .from_json_hash(hash[:assignee]) + hash[:assignee] &&= Representation::User.from_json_hash(hash[:assignee]) + hash[:merged_by] &&= Representation::User.from_json_hash(hash[:merged_by]) new(hash) end 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 |