Class: Labelito::GithubClient
- Inherits:
-
Object
- Object
- Labelito::GithubClient
- Defined in:
- lib/Labelito/github_client.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client) ⇒ GithubClient
constructor
A new instance of GithubClient.
- #labels(repository) ⇒ Object
- #update(labels, repository) ⇒ Object
Constructor Details
#initialize(client) ⇒ GithubClient
Returns a new instance of GithubClient.
7 8 9 |
# File 'lib/Labelito/github_client.rb', line 7 def initialize(client) @client = client end |
Class Method Details
.with_token(token) ⇒ Object
11 12 13 |
# File 'lib/Labelito/github_client.rb', line 11 def self.with_token(token) GithubClient.new Octokit::Client.new(:access_token => token) end |
Instance Method Details
#labels(repository) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/Labelito/github_client.rb', line 15 def labels(repository) puts "=> Fetching labels" @client.labels(repository).map do |label| Label.from_github_label(label) end end |
#update(labels, repository) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/Labelito/github_client.rb', line 22 def update(labels, repository) old_labels = @client.labels(repository) puts "=> Deleting existing labels" old_labels.each { |label| puts "==> Deleting label #{label[:name]}" @client.delete_label!(repository, label[:name]) } labels.each do |label| puts "==> Creating label #{label.name}" @client.add_label(repository, label.name, label.color) end end |