diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2016-10-28 08:48:08 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2016-10-28 08:48:08 +0000 |
commit | 66870960af8d8a4cafec4abc529bd073d23fd1e4 (patch) | |
tree | 742bd65b043cfcc3e6190d40953d41fa70cc6bdb /lib | |
parent | 20a7db4483904c7280093a0309a63dfd1b7ef72e (diff) | |
parent | ce38ae8ca15714e710c5198d201336f3651ad788 (diff) | |
download | gitlab-ce-66870960af8d8a4cafec4abc529bd073d23fd1e4.tar.gz |
Merge branch 'fix/gh-import-bugs' into 'master'
Fix couple of GitHub importing bugs
Fix a bug in GH comment importing and label applying for imported MRs.
See merge request !7139
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/github_import/client.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/github_import/importer.rb | 24 |
2 files changed, 23 insertions, 13 deletions
diff --git a/lib/gitlab/github_import/client.rb b/lib/gitlab/github_import/client.rb index 7f424b74efb..348005d5659 100644 --- a/lib/gitlab/github_import/client.rb +++ b/lib/gitlab/github_import/client.rb @@ -105,18 +105,20 @@ module Gitlab data = api.send(method, *args) return data unless data.is_a?(Array) + last_response = api.last_response + if block_given? yield data - each_response_page(&block) + # api.last_response could change while we're yielding (e.g. fetching labels for each PR) + # so we cache our own last request + each_response_page(last_response, &block) else - each_response_page { |page| data.concat(page) } + each_response_page(last_response) { |page| data.concat(page) } data end end - def each_response_page - last_response = api.last_response - + def each_response_page(last_response) while last_response.rels[:next] sleep rate_limit_sleep_time if rate_limit_exceed? last_response = last_response.rels[:next].get diff --git a/lib/gitlab/github_import/importer.rb b/lib/gitlab/github_import/importer.rb index 4b70f33a851..27946dff608 100644 --- a/lib/gitlab/github_import/importer.rb +++ b/lib/gitlab/github_import/importer.rb @@ -132,8 +132,15 @@ module Gitlab end def apply_labels(issuable, raw_issuable) - if raw_issuable.labels.count > 0 - label_ids = raw_issuable.labels + # GH returns labels for issues but not for pull requests! + labels = if issuable.is_a?(MergeRequest) + client.labels_for_issue(repo, raw_issuable.number) + else + raw_issuable.labels + end + + if labels.count > 0 + label_ids = labels .map { |attrs| @labels[attrs.name] } .compact @@ -143,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 |