gitlab-org--gitlab-foss/lib/gitlab/bitbucket_import/key_adder.rb

25 lines
663 B
Ruby
Raw Normal View History

2015-02-17 10:59:50 -05:00
module Gitlab
module BitbucketImport
class KeyAdder
attr_reader :repo, :current_user, :client
def initialize(repo, current_user, access_params)
2015-02-17 10:59:50 -05:00
@repo, @current_user = repo, current_user
@client = Client.new(access_params[:bitbucket_access_token],
access_params[:bitbucket_access_token_secret])
2015-02-17 10:59:50 -05:00
end
def execute
2015-02-17 16:52:32 -05:00
return false unless BitbucketImport.public_key.present?
2015-02-17 10:59:50 -05:00
project_identifier = "#{repo["owner"]}/#{repo["slug"]}"
2015-02-17 16:52:32 -05:00
client.add_deploy_key(project_identifier, BitbucketImport.public_key)
2015-02-17 10:59:50 -05:00
true
2015-02-17 16:52:32 -05:00
rescue
false
2015-02-17 10:59:50 -05:00
end
end
end
end