diff options
author | James Lopez <james@jameslopez.es> | 2016-03-22 19:53:53 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-03-22 19:53:53 +0300 |
commit | 8aafe685837d12b623f70eec86cae6e7cef9a849 (patch) | |
tree | 2624e269085d65633c29f39e3ed765de8178ea5b /lib/gitlab/bitbucket_import | |
parent | 3b78885eac025b5cf90e1a370b7bbbbd88cc9727 (diff) |
first round of fixes and spec fixes
Diffstat (limited to 'lib/gitlab/bitbucket_import')
-rw-r--r-- | lib/gitlab/bitbucket_import/importer.rb | 19 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/importer_init.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/key_deleter.rb | 13 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/project_creator.rb | 4 |
4 files changed, 32 insertions, 31 deletions
diff --git a/lib/gitlab/bitbucket_import/importer.rb b/lib/gitlab/bitbucket_import/importer.rb index 36110962e0c..f80410641a9 100644 --- a/lib/gitlab/bitbucket_import/importer.rb +++ b/lib/gitlab/bitbucket_import/importer.rb @@ -1,19 +1,6 @@ module Gitlab module BitbucketImport - class Importer - attr_reader :project, :client - - def initialize(project) - @project = project - if import_data_credentials && import_data_credentials['bb_session'] - token = import_data_credentials['bb_session']['bitbucket_access_token'] - token_secret = import_data_credentials['bb_session']['bitbucket_access_token_secret'] - @client = Client.new(token, token_secret) - @formatter = Gitlab::ImportFormatter.new - else - raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}" - end - end + class Importer < ImporterInit def execute import_issues if has_issues? @@ -27,10 +14,6 @@ module Gitlab private - def import_data_credentials - @import_data_credentials ||= project.import_data.credentials if project.import_data - end - def gl_user_id(project, bitbucket_id) if bitbucket_id user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", bitbucket_id.to_s) diff --git a/lib/gitlab/bitbucket_import/importer_init.rb b/lib/gitlab/bitbucket_import/importer_init.rb new file mode 100644 index 00000000000..6d81811d36b --- /dev/null +++ b/lib/gitlab/bitbucket_import/importer_init.rb @@ -0,0 +1,27 @@ +module Gitlab + module BitbucketImport + class ImporterInit + attr_reader :project, :client + + def initialize(project) + @project = project + if import_data_credentials && import_data_credentials['bb_session'] + token = import_data_credentials['bb_session']['bitbucket_access_token'] + token_secret = import_data_credentials['bb_session']['bitbucket_access_token_secret'] + @client = Client.new(token, token_secret) + @formatter = Gitlab::ImportFormatter.new + else + raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}" + end + end + + private + + def import_data_credentials + @import_data_credentials ||= project.import_data.credentials if project.import_data + end + end + end +end + + diff --git a/lib/gitlab/bitbucket_import/key_deleter.rb b/lib/gitlab/bitbucket_import/key_deleter.rb index f4dd393ad29..312ed581500 100644 --- a/lib/gitlab/bitbucket_import/key_deleter.rb +++ b/lib/gitlab/bitbucket_import/key_deleter.rb @@ -1,16 +1,7 @@ module Gitlab module BitbucketImport - class KeyDeleter - attr_reader :project, :current_user, :client - - def initialize(project) - @project = project - @current_user = project.creator - import_data = project.import_data.try(:data) - bb_session = import_data["bb_session"] if import_data - @client = Client.new(bb_session["bitbucket_access_token"], - bb_session["bitbucket_access_token_secret"]) - end + class KeyDeleter < ImporterInit + attr_reader :current_user def execute return false unless BitbucketImport.public_key.present? diff --git a/lib/gitlab/bitbucket_import/project_creator.rb b/lib/gitlab/bitbucket_import/project_creator.rb index c9ccecef0c3..0e6f66de321 100644 --- a/lib/gitlab/bitbucket_import/project_creator.rb +++ b/lib/gitlab/bitbucket_import/project_creator.rb @@ -22,8 +22,8 @@ module Gitlab import_source: "#{repo["owner"]}/#{repo["slug"]}", import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git", ).execute - - project.create_import_data(credentials: { "bb_session" => session_data } ) + import_data = project.import_data + import_data.credentials.merge!("bb_session" => session_data) project end end |