From ce38ae8ca15714e710c5198d201336f3651ad788 Mon Sep 17 00:00:00 2001 From: Ahmad Sherif Date: Thu, 27 Oct 2016 15:08:37 +0200 Subject: Fix importing MR comments from GitHub --- CHANGELOG.md | 1 + lib/gitlab/github_import/importer.rb | 13 +++++++------ 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 -- cgit v1.2.1