2015-04-26 12:48:37 +05:30
|
|
|
module Gitlab
|
|
|
|
module BitbucketImport
|
|
|
|
class KeyAdder
|
|
|
|
attr_reader :repo, :current_user, :client
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
def initialize(repo, current_user, access_params)
|
2015-04-26 12:48:37 +05:30
|
|
|
@repo, @current_user = repo, current_user
|
2015-09-25 12:07:36 +05:30
|
|
|
@client = Client.new(access_params[:bitbucket_access_token],
|
|
|
|
access_params[:bitbucket_access_token_secret])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
return false unless BitbucketImport.public_key.present?
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
project_identifier = "#{repo["owner"]}/#{repo["slug"]}"
|
|
|
|
client.add_deploy_key(project_identifier, BitbucketImport.public_key)
|
|
|
|
|
|
|
|
true
|
|
|
|
rescue
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|