Class: GitDuplicator::Services::GithubRepository
- Inherits:
-
GitDuplicator::ServiceRepository
- Object
- Repository
- GitDuplicator::ServiceRepository
- GitDuplicator::Services::GithubRepository
- Defined in:
- lib/git_duplicator/services/github.rb
Constant Summary collapse
- BASE_URI =
'https://api.github.com'
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#remote_options ⇒ Object
Returns the value of attribute remote_options.
-
#working_directory ⇒ Object
Returns the value of attribute working_directory.
Attributes inherited from GitDuplicator::ServiceRepository
Attributes inherited from Repository
Instance Method Summary collapse
-
#create ⇒ Object
Create the repository.
-
#delete ⇒ Object
Delete the repositroy.
-
#initialize(name, owner, options = {}) ⇒ GithubRepository
constructor
Initializer.
-
#url ⇒ Object
URL of the repositroy.
Methods inherited from Repository
#bare_clone, #mirror, #mirror_clone, #set_mirrored_remote, #update_mirrored
Constructor Details
#initialize(name, owner, options = {}) ⇒ GithubRepository
Initializer
18 19 20 21 22 23 |
# File 'lib/git_duplicator/services/github.rb', line 18 def initialize(name, owner, = {}) self.credentials = .fetch(:credentials) { {} } self. = .fetch(:remote_options) { {} } self.working_directory = .fetch(:working_directory) { nil } super(name, owner, working_directory) end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
7 8 9 |
# File 'lib/git_duplicator/services/github.rb', line 7 def credentials @credentials end |
#remote_options ⇒ Object
Returns the value of attribute remote_options.
7 8 9 |
# File 'lib/git_duplicator/services/github.rb', line 7 def end |
#working_directory ⇒ Object
Returns the value of attribute working_directory.
7 8 9 |
# File 'lib/git_duplicator/services/github.rb', line 7 def working_directory @working_directory end |
Instance Method Details
#create ⇒ Object
Create the repository
32 33 34 35 36 37 38 |
# 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: .merge(name: name)) code, body = response.code.to_i, response.body fail(RepositoryCreationError, body) unless 201 == code end |
#delete ⇒ Object
Delete the repositroy
42 43 44 45 46 47 |
# 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 ⇒ Object
URL of the repositroy
26 27 28 |
# File 'lib/git_duplicator/services/github.rb', line 26 def url "[email protected]:#{owner}/#{name}.git" end |