update bitbucket importer

This commit is contained in:
James Lopez 2016-03-22 12:25:28 +01:00
parent 1b8d995492
commit 23146fca18
3 changed files with 14 additions and 7 deletions

View file

@ -71,7 +71,7 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
# All bitbucket imports # All bitbucket imports
def bitbucket_projects_with_wrong_import_url def bitbucket_projects_with_wrong_import_url
select_all("SELECT p.id, p.import_urlselect_all("SELECT i.id, p.import_url, i.data FROM projects p INNER JOIN project_import_data i ON p.id = i.project_id WHERE p.import_url IS NOT NULL AND p.import_type = 'bitbucket' "), i.data FROM projects p INNER JOIN project_import_data i ON p.id = i.project_id WHERE p.import_url IS NOT NULL AND p.import_type = 'bitbucket' ") select_all("SELECT i.id, p.import_url, i.data FROM projects p INNER JOIN project_import_data i ON p.id = i.project_id WHERE p.import_url IS NOT NULL AND p.import_type = 'bitbucket' ")
end end
def project_import_data(project_id) def project_import_data(project_id)

View file

@ -5,11 +5,14 @@ module Gitlab
def initialize(project) def initialize(project)
@project = project @project = project
import_data = project.import_data.try(:data) if import_data_credentials && import_data_credentials['bb_session']
bb_session = import_data["bb_session"] if import_data token = import_data_credentials['bb_session']['bitbucket_access_token']
@client = Client.new(bb_session["bitbucket_access_token"], token_secret = import_data_credentials['bb_session']['bitbucket_access_token_secret']
bb_session["bitbucket_access_token_secret"]) @client = Client.new(token, token_secret)
@formatter = Gitlab::ImportFormatter.new @formatter = Gitlab::ImportFormatter.new
else
raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"
end
end end
def execute def execute
@ -24,6 +27,10 @@ module Gitlab
private private
def import_data_credentials
@import_data_credentials ||= project.import_data.credentials if project.import_data
end
def gl_user_id(project, bitbucket_id) def gl_user_id(project, bitbucket_id)
if bitbucket_id if bitbucket_id
user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", bitbucket_id.to_s) user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", bitbucket_id.to_s)

View file

@ -8,7 +8,7 @@ module Gitlab
def initialize(project) def initialize(project)
@project = project @project = project
if import_data_credentials if import_data_credentials
@client = Client.new(import_data_credentials[:user]) @client = Client.new(import_data_credentials['user'])
@formatter = Gitlab::ImportFormatter.new @formatter = Gitlab::ImportFormatter.new
else else
raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}" raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"