summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2016-09-27 19:41:22 +0200
committerAhmad Sherif <me@ahmadsherif.com>2016-09-27 20:45:07 +0200
commite30bfb809afdbf5596176cf0fe0ea63e976cbb9f (patch)
tree7c6fbc28821ccb8764594adc7cb6aba63b6332c2
parentdbcbbf262b731e30446167fbd10ef081d195c862 (diff)
downloadgitlab-ce-e30bfb809afdbf5596176cf0fe0ea63e976cbb9f.tar.gz
Import all GitHub comments after importing issues and PRs
-rw-r--r--lib/gitlab/github_import/importer.rb27
-rw-r--r--spec/lib/gitlab/github_import/importer_spec.rb2
2 files changed, 17 insertions, 12 deletions
diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb
index 31fba36de7e..1d385dba0f5 100644
--- a/lib/gitlab/github_import/importer.rb
+++ b/lib/gitlab/github_import/importer.rb
@@ -24,6 +24,7 @@ module Gitlab
import_milestones
import_issues
import_pull_requests
+ import_comments
import_wiki
import_releases
handle_errors
@@ -80,7 +81,6 @@ module Gitlab
begin
issue = gh_issue.create!
apply_labels(issue, raw)
- import_comments(issue) if gh_issue.has_comments?
rescue => e
errors << { type: :issue, url: Gitlab::UrlSanitizer.sanitize(raw.url), errors: e.message }
end
@@ -101,8 +101,6 @@ module Gitlab
merge_request = pull_request.create!
apply_labels(merge_request, raw)
- import_comments(merge_request)
- import_comments_on_diff(merge_request)
rescue => e
errors << { type: :pull_request, url: Gitlab::UrlSanitizer.sanitize(pull_request.url), errors: e.message }
ensure
@@ -143,21 +141,26 @@ module Gitlab
end
end
- def import_comments(issuable)
- comments = client.issue_comments(repo, issuable.iid, per_page: 100)
- create_comments(issuable, comments)
- end
+ def import_comments
+ client.issues_comments(repo, per_page: 100) do |comments|
+ create_comments(comments, :issue)
+ end
- def import_comments_on_diff(merge_request)
- comments = client.pull_request_comments(repo, merge_request.iid, per_page: 100)
- create_comments(merge_request, comments)
+ client.pull_requests_comments(repo, per_page: 100) do |comments|
+ create_comments(comments, :pull_request)
+ end
end
- def create_comments(issuable, comments)
+ def create_comments(comments, issuable_type)
ActiveRecord::Base.no_touching do
comments.each do |raw|
begin
- comment = CommentFormatter.new(project, raw)
+ comment = CommentFormatter.new(project, raw)
+ issuable_class = issuable_type == :issue ? Issue : MergeRequest
+ iid = raw.send("#{issuable_type}_url").split('/').last # GH doesn't return parent ID directly
+ issuable = issuable_class.find_by_iid(iid)
+ next unless issuable
+
issuable.notes.create!(comment.attributes)
rescue => e
errors << { type: :comment, url: Gitlab::UrlSanitizer.sanitize(raw.url), errors: e.message }
diff --git a/spec/lib/gitlab/github_import/importer_spec.rb b/spec/lib/gitlab/github_import/importer_spec.rb
index 844c081fc7f..8854c8431b5 100644
--- a/spec/lib/gitlab/github_import/importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer_spec.rb
@@ -132,6 +132,8 @@ describe Gitlab::GithubImport::Importer, lib: true do
allow_any_instance_of(Octokit::Client).to receive(:milestones).and_return([milestone, milestone])
allow_any_instance_of(Octokit::Client).to receive(:issues).and_return([issue1, issue2])
allow_any_instance_of(Octokit::Client).to receive(:pull_requests).and_return([pull_request, pull_request])
+ allow_any_instance_of(Octokit::Client).to receive(:issues_comments).and_return([])
+ allow_any_instance_of(Octokit::Client).to receive(:pull_requests_comments).and_return([])
allow_any_instance_of(Octokit::Client).to receive(:last_response).and_return(double(rels: { next: nil }))
allow_any_instance_of(Octokit::Client).to receive(:releases).and_return([release1, release2])
allow_any_instance_of(Gitlab::Shell).to receive(:import_repository).and_raise(Gitlab::Shell::Error)