class GitDuplicator::Services::BitbucketRepository
Bitbucket based repository
Constants
- BASE_URI
Attributes
credentials[RW]
remote_options[RW]
Public Class Methods
new(name, owner, options = {})
click to toggle source
Initializer @param [String] name name of the repository @param [String] owner owner of the repository @param [Hash] options
* :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
Calls superclass method
GitDuplicator::ServiceRepository::new
# 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
Public Instance Methods
create()
click to toggle source
Create the repositroy @see confluence.atlassian.com/display/BITBUCKET/repository+Resource#repositoryResource-POSTanewrepository
# 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
delete()
click to toggle source
Delete the repositroy @see confluence.atlassian.com/display/BITBUCKET/repository+Resource#repositoryResource-DELETEarepository
# 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
url()
click to toggle source
URL of the repositroy
# File lib/git_duplicator/services/bitbucket.rb, line 32 def url "git@bitbucket.org:#{owner}/#{name}.git" end
Private Instance Methods
headers(method, url)
click to toggle source
# File lib/git_duplicator/services/bitbucket.rb, line 57 def headers(method, url) { 'Content-Type' => 'application/json', 'Authorization' => Helpers::AuthorizationHeader.new( credentials, method: method, url: url ).generate } end