summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2016-10-27 15:08:37 +0200
committerAhmad Sherif <me@ahmadsherif.com>2016-10-27 15:42:29 +0200
commitce38ae8ca15714e710c5198d201336f3651ad788 (patch)
tree38d5d31f92de1b86c8f15faeab7bdf4b76029c16
parent4259334fb64ef49580e58d434bc63d3c4738a77c (diff)
downloadgitlab-ce-ce38ae8ca15714e710c5198d201336f3651ad788.tar.gz
Fix importing MR comments from GitHubfix/gh-import-bugs
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/gitlab/github_import/importer.rb13
2 files changed, 8 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6bf63582cbd..1cd16ca4ccd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,7 @@ Please view this file on the master branch, on stable branches it's out of date.
- Show full status link on MR & commit pipelines
- Fix documents and comments on Build API `scope`
- Fix applying labels for GitHub-imported MRs
+ - Fix importing MR comments from GitHub
- Refactor email, use setter method instead AR callbacks for email attribute (Semyon Pupkov)
## 8.13.1 (2016-10-25)
diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb
index 4ac932dc213..27946dff608 100644
--- a/lib/gitlab/github_import/importer.rb
+++ b/lib/gitlab/github_import/importer.rb
@@ -150,21 +150,22 @@ module Gitlab
def import_comments
client.issues_comments(repo, per_page: 100) do |comments|
- create_comments(comments, :issue)
+ create_comments(comments)
end
client.pull_requests_comments(repo, per_page: 100) do |comments|
- create_comments(comments, :pull_request)
+ create_comments(comments)
end
end
- def create_comments(comments, issuable_type)
+ def create_comments(comments)
ActiveRecord::Base.no_touching do
comments.each do |raw|
begin
- 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
+ comment = CommentFormatter.new(project, raw)
+ # GH does not return info about comment's parent, so we guess it by checking its URL!
+ *_, parent, iid = URI(raw.html_url).path.split('/')
+ issuable_class = parent == 'issues' ? Issue : MergeRequest
issuable = issuable_class.find_by_iid(iid)
next unless issuable