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, #repo

Instance Method Summary collapse

Methods inherited from Repository

#bare_clone, #mirror

Constructor Details

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

Initializer

Parameters:

  • name (String)

    name of the repository

  • owner (String)

    owner of the repository

  • credentials (Hash) (defaults to: {})
  • options (Hash) (defaults to: {})

    options for creation

Options Hash (credentials):

  • :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

See Also:



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

def initialize(name, owner, credentials = {}, options = {})
  super(name, owner)
  self.credentials = credentials
  self.options = options
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



10
11
12
# File 'lib/git_duplicator/services/bitbucket.rb', line 10

def credentials
  @credentials
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/git_duplicator/services/bitbucket.rb', line 10

def options
  @options
end

Instance Method Details

#createObject

Create the repositroy



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

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

#deleteObject

Delete the repositroy



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

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



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

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