Commit ce38ae8c authored by Ahmad Sherif's avatar Ahmad Sherif

Fix importing MR comments from GitHub

parent 4259334f
...@@ -27,6 +27,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -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 - Show full status link on MR & commit pipelines
- Fix documents and comments on Build API `scope` - Fix documents and comments on Build API `scope`
- Fix applying labels for GitHub-imported MRs - 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) - Refactor email, use setter method instead AR callbacks for email attribute (Semyon Pupkov)
## 8.13.1 (2016-10-25) ## 8.13.1 (2016-10-25)
......
...@@ -150,21 +150,22 @@ module Gitlab ...@@ -150,21 +150,22 @@ module Gitlab
def import_comments def import_comments
client.issues_comments(repo, per_page: 100) do |comments| client.issues_comments(repo, per_page: 100) do |comments|
create_comments(comments, :issue) create_comments(comments)
end end
client.pull_requests_comments(repo, per_page: 100) do |comments| client.pull_requests_comments(repo, per_page: 100) do |comments|
create_comments(comments, :pull_request) create_comments(comments)
end end
end end
def create_comments(comments, issuable_type) def create_comments(comments)
ActiveRecord::Base.no_touching do ActiveRecord::Base.no_touching do
comments.each do |raw| comments.each do |raw|
begin begin
comment = CommentFormatter.new(project, raw) comment = CommentFormatter.new(project, raw)
issuable_class = issuable_type == :issue ? Issue : MergeRequest # GH does not return info about comment's parent, so we guess it by checking its URL!
iid = raw.send("#{issuable_type}_url").split('/').last # GH doesn't return parent ID directly *_, parent, iid = URI(raw.html_url).path.split('/')
issuable_class = parent == 'issues' ? Issue : MergeRequest
issuable = issuable_class.find_by_iid(iid) issuable = issuable_class.find_by_iid(iid)
next unless issuable next unless issuable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment