BigW Consortium Gitlab

key_adder.rb 663 Bytes
Newer Older
Douwe Maan committed
1 2 3 4 5
module Gitlab
  module BitbucketImport
    class KeyAdder
      attr_reader :repo, :current_user, :client

6
      def initialize(repo, current_user, access_params)
Douwe Maan committed
7
        @repo, @current_user = repo, current_user
8 9
        @client = Client.new(access_params[:bitbucket_access_token],
                             access_params[:bitbucket_access_token_secret])
Douwe Maan committed
10 11 12
      end

      def execute
13
        return false unless BitbucketImport.public_key.present?
14

Douwe Maan committed
15
        project_identifier = "#{repo["owner"]}/#{repo["slug"]}"
16
        client.add_deploy_key(project_identifier, BitbucketImport.public_key)
Douwe Maan committed
17 18

        true
19 20
      rescue
        false
Douwe Maan committed
21 22 23 24
      end
    end
  end
end