class GitDuplicator::Services::GithubRepository

Constants

BASE_URI

Attributes

credentials[RW]
remote_options[RW]
working_directory[RW]

Public Class Methods

new(name, owner, options = {}) click to toggle source

Initializer @param [Hash] options

* :credentials (Hash) credentials for remote service
  * :oauth2_token (Symbol) used in oAuth2 authentication
  * :username (Symbol) used in basic authentication
  * :password (Symbol) used in basic authentication
* :remote_options (Hash) creation options for remote service
 @see @see https://developer.github.com/v3/repos/#create
* :working_directory (String) assing a working directory
Calls superclass method GitDuplicator::ServiceRepository::new
# File lib/git_duplicator/services/github.rb, line 18
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 repository @see developer.github.com/v3/repos/#create

# File lib/git_duplicator/services/github.rb, line 32
def create
  request_url = BASE_URI + '/user/repos'
  response = HTTP.with(headers(:post, request_url))
  .post(request_url, json: remote_options.merge(name: name))
  code, body = response.code.to_i, response.body
  fail(RepositoryCreationError, body) unless 201 == code
end
delete() click to toggle source

Delete the repositroy @see developer.github.com/v3/repos/#delete-a-repository

# File lib/git_duplicator/services/github.rb, line 42
def delete
  request_url = BASE_URI + "/repos/#{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/github.rb, line 26
def url
  "git@github.com:#{owner}/#{name}.git"
end

Private Instance Methods

headers(method, url) click to toggle source
# File lib/git_duplicator/services/github.rb, line 51
def headers(method, url)
  {
    'Accept' => 'application/vnd.github.v3+json',
    'Authorization' =>
    Helpers::AuthorizationHeader.new(
      credentials, method: method, url: url
    ).generate
  }
end