Class: GitDuplicator::Services::BitbucketRepository

Inherits:
GitDuplicator::ServiceRepository show all
Defined in:
lib/git_duplicator/services/bitbucket.rb

Overview

Bitbucket based repository

Constant Summary collapse

BASE_URI =
'https://api.bitbucket.org/2.0'

Instance Attribute Summary collapse

Attributes inherited from GitDuplicator::ServiceRepository

#owner

Attributes inherited from Repository

#name, #working_directory

Instance Method Summary collapse

Methods inherited from Repository

#bare_clone, #mirror, #mirror_clone, #set_mirrored_remote, #update_mirrored

Constructor Details

#initialize(name, owner, options = {}) ⇒ BitbucketRepository

Initializer

Parameters:

  • name (String)

    name of the repository

  • owner (String)

    owner of the repository

  • options (Hash) (defaults to: {})
    • :credentials (Hash) credentials for remote service
      • :consumer_key (Symbol) used in oAuth authentication
      • :consumer_secret (Symbol) used in oAuth authentication
      • :token (Symbol) used in oAuth authentication
      • :token_secret (Symbol) used in oAuth authentication
      • :username (Symbol) used in basic authentication
      • :password (Symbol) used in basic authentication
    • :remote_options (Hash) creation options for remote service @see https://confluence.atlassian.com/display/BITBUCKET/repository+Resource#repositoryResource-POSTanewrepository
    • :working_directory (String) assing a working directory


24
25
26
27
28
29
# File 'lib/git_duplicator/services/bitbucket.rb', line 24

def initialize(name, owner, options = {})
  self.credentials = options.fetch(:credentials) { {} }
  self.remote_options = options.fetch(:remote_options) { {} }
  self.working_directory = options.fetch(:working_directory) { nil }
  super(name, owner, working_directory)
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



8
9
10
# File 'lib/git_duplicator/services/bitbucket.rb', line 8

def credentials
  @credentials
end

#remote_optionsObject

Returns the value of attribute remote_options.



8
9
10
# File 'lib/git_duplicator/services/bitbucket.rb', line 8

def remote_options
  @remote_options
end

Instance Method Details

#createObject

Create the repositroy



38
39
40
41
42
43
44
# File 'lib/git_duplicator/services/bitbucket.rb', line 38

def create
  request_url = BASE_URI + "/repositories/#{owner}/#{name}"
  response = HTTP.with(headers(:post, request_url))
  .post(request_url, json: remote_options)
  code, body = response.code.to_i, response.body
  fail(RepositoryCreationError, body) unless 200 == code
end

#deleteObject

Delete the repositroy



48
49
50
51
52
53
# File 'lib/git_duplicator/services/bitbucket.rb', line 48

def delete
  request_url = BASE_URI + "/repositories/#{owner}/#{name}"
  response = HTTP.with(headers(:delete, request_url)).delete(request_url)
  code, body = response.code.to_i, response.body
  fail(RepositoryDeletionError, body) unless [204, 404].include?(code)
end

#urlObject

URL of the repositroy



32
33
34
# File 'lib/git_duplicator/services/bitbucket.rb', line 32

def url
  "[email protected]:#{owner}/#{name}.git"
end