From 3b4e81eed50dac796de5720b9975125dc8de609b Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Fri, 16 Dec 2016 12:12:53 +0200 Subject: BB importer: Milestone importer --- lib/bitbucket/representation/issue.rb | 4 ++++ lib/gitlab/bitbucket_import/importer.rb | 2 ++ spec/lib/bitbucket/representation/issue_spec.rb | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/lib/bitbucket/representation/issue.rb b/lib/bitbucket/representation/issue.rb index ffe8a65d839..3af731753d1 100644 --- a/lib/bitbucket/representation/issue.rb +++ b/lib/bitbucket/representation/issue.rb @@ -27,6 +27,10 @@ module Bitbucket raw['title'] end + def milestone + raw.dig('milestone', 'name') + end + def created_at raw['created_on'] end diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb index 567f2b314aa..53c95ea4079 100644 --- a/lib/gitlab/bitbucket_import/importer.rb +++ b/lib/gitlab/bitbucket_import/importer.rb @@ -67,6 +67,7 @@ module Gitlab description += issue.description label_name = issue.kind + milestone = issue.milestone ? project.milestones.find_or_create_by(title: issue.milestone) : nil issue = project.issues.create!( iid: issue.iid, @@ -74,6 +75,7 @@ module Gitlab description: description, state: issue.state, author_id: gitlab_user_id(project, issue.author), + milestone: milestone, created_at: issue.created_at, updated_at: issue.updated_at ) diff --git a/spec/lib/bitbucket/representation/issue_spec.rb b/spec/lib/bitbucket/representation/issue_spec.rb index e1f3419c77e..9a195bebd31 100644 --- a/spec/lib/bitbucket/representation/issue_spec.rb +++ b/spec/lib/bitbucket/representation/issue_spec.rb @@ -9,6 +9,12 @@ describe Bitbucket::Representation::Issue do it { expect(described_class.new('kind' => 'bug').kind).to eq('bug') } end + describe '#milestone' do + it { expect(described_class.new({ 'milestone' => { 'name' => '1.0' } }).milestone).to eq('1.0') } + it { expect(described_class.new({}).milestone).to be_nil } + end + + describe '#author' do it { expect(described_class.new({ 'reporter' => { 'username' => 'Ben' } }).author).to eq('Ben') } it { expect(described_class.new({}).author).to be_nil } -- cgit v1.2.3 From b0501c34c478a528f2aa7633dfa6d13e9c61af64 Mon Sep 17 00:00:00 2001 From: Valery Sizov Date: Fri, 16 Dec 2016 15:40:38 +0200 Subject: BB importer: address review comment --- doc/workflow/importing/import_projects_from_bitbucket.md | 2 +- lib/gitlab/bitbucket_import/importer.rb | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/workflow/importing/import_projects_from_bitbucket.md b/doc/workflow/importing/import_projects_from_bitbucket.md index 935d6288f3b..9e1e3c7ba08 100644 --- a/doc/workflow/importing/import_projects_from_bitbucket.md +++ b/doc/workflow/importing/import_projects_from_bitbucket.md @@ -20,7 +20,7 @@ It takes just a few steps to import your existing Bitbucket projects to GitLab. ![Import projects](bitbucket_importer/bitbucket_import_select_project.png) -A new GitLab project will be created with your imported data. Keep in mind that if you want to Bitbucket users +A new GitLab project will be created with your imported data. Keep in mind that if you want Bitbucket users to be linked to GitLab user you have to have all of them in GitLab in advance. They will be matched by their BitBucket username. ### Note diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb index 53c95ea4079..63a4407cb78 100644 --- a/lib/gitlab/bitbucket_import/importer.rb +++ b/lib/gitlab/bitbucket_import/importer.rb @@ -28,6 +28,7 @@ module Gitlab def handle_errors return unless errors.any? + project.update_column(:import_error, { message: 'The remote data could not be fully imported.', errors: errors @@ -35,15 +36,12 @@ module Gitlab end def gitlab_user_id(project, username) - if username - user = find_user(username) - (user && user.id) || project.creator_id - else - project.creator_id - end + user = find_user(username) + user.try(:id) || project.creator_id end def find_user(username) + return nil unless username User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", username) end -- cgit v1.2.3