class CopyGithubLabels::Client
Attributes
client[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/copy_github_labels/client.rb, line 8 def initialize(opts = {}) @client = Octokit::Client.new(opts) @client.auto_paginate = true end
Public Instance Methods
copy_labels(source, target, opts = {})
click to toggle source
# File lib/copy_github_labels/client.rb, line 17 def copy_labels(source, target, opts = {}) labels(source).map do |label| Thread.new do msg = copy_label(label, target, opts) puts msg.join(" ") end end.each(&:join) puts "DONE".green end
labels(repo)
click to toggle source
# File lib/copy_github_labels/client.rb, line 13 def labels(repo) client.labels(repo) end
Private Instance Methods
add_label(repo, label, color, description = "")
click to toggle source
# File lib/copy_github_labels/client.rb, line 53 def add_label(repo, label, color, description = "") client.add_label(repo, label, color, { description: description }) end
copy_label(label, target_repo, opts = {})
click to toggle source
# File lib/copy_github_labels/client.rb, line 29 def copy_label(label, target_repo, opts = {}) msg = [label.name.blue, ":"] begin add_label(target_repo, label.name, label.color) msg << "OK".green rescue Octokit::UnprocessableEntity => error if error.message =~ /already_exists/ if opts[:override] update_label(target_repo, label.name, { color: label.color, description: label.description }) msg += ["OK".green, "OVERRIDE".yellow] else msg << "SKIP".yellow end else msg += ["ERROR".red, error.message.light_black] end rescue => error msg += ["ERROR".red, error.message.light_black] end msg end
update_label(repo, label, opts = {})
click to toggle source
# File lib/copy_github_labels/client.rb, line 57 def update_label(repo, label, opts = {}) client.update_label(repo, label, opts) end