Fix importing MR comments from GitHub
This commit is contained in:
parent
4259334fb6
commit
ce38ae8ca1
2 changed files with 8 additions and 6 deletions
|
@ -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
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue