class LabelMaker::Repo
Public Class Methods
new()
click to toggle source
# File lib/label_maker/repo.rb, line 4 def initialize @client = LabelMaker::User.new.github_client end
Public Instance Methods
add_labels_to_target()
click to toggle source
# File lib/label_maker/repo.rb, line 95 def add_labels_to_target @target_labels = @client.labels(@repo_target) @target_labels = Hash[@target_labels.map {|l| [l.name, l.color]}] puts "Copying #{@source_repo}" @source_labels.each do |s_key, s_value| if @target_labels.include?(s_key) if @target_labels[s_key] == s_value puts " Already Exsists - color: #{s_value} with name: #{s_key}" else puts " Updating - color: #{s_value} with name: #{s_key}" @client.update_label(@repo_target, s_key, {color: "#{s_value}"}) end else puts " Adding - color: #{s_value} with name: #{s_key}" @client.add_label(@repo_target, s_key, s_value) end end end
add_source_labels()
click to toggle source
# File lib/label_maker/repo.rb, line 55 def add_source_labels @repo_target = @target_repo if @clear_labels == "y" clear_all_labels else add_labels_to_target end puts " Labels from #{@source_repo} have been copied to #{@repo_target}" puts "" end
clear_all_labels()
click to toggle source
# File lib/label_maker/repo.rb, line 68 def clear_all_labels t_labels_in_repo = @client.labels(@repo_target) t_labels_in_repo = Hash[t_labels_in_repo.map {|l| [l.name, l.color]}] target_issue_labels = [] puts "Deleting labels from #{@repo_target} that are not associated with an issue!" issues_with_target_repo = @client.list_issues(@repo_target, options= {state: "all"}) issues_with_target_repo.each do |issue| if issue.labels != [] issue.labels.each do |label| target_issue_labels << label.name end end end target_issue_labels = target_issue_labels.uniq t_labels_in_repo.each_key do |t_label| if target_issue_labels.include?(t_label) != true @client.delete_label!(@repo_target, t_label) puts " Deleting #{t_label}" else puts " Ignoring #{t_label}" end end puts "" add_labels_to_target end
copy_to_all_repos()
click to toggle source
# File lib/label_maker/repo.rb, line 24 def copy_to_all_repos puts "This may take awhile!" if @target_repo.start_with?(@client.login) @client.repositories.each do |repo| @repo_target = repo.full_name if @clear_labels == "y" clear_all_labels else add_labels_to_target end puts " Labels from #{@source_repo} have been copied to #{@repo_target}" puts "" end else org = @target_repo.chomp("/*") @client.org_repos(org).each do |repo| @repo_target = repo.full_name if @clear_labels == "y" clear_all_labels else add_labels_to_target end puts " Labels from #{@source_repo} have been copied to #{@repo_target}" puts "" end end end
repo_questions()
click to toggle source
# File lib/label_maker/repo.rb, line 8 def repo_questions puts "Source repo (ex. username/source-repo):" @source_repo = gets.chomp puts "Target repo (ex. username/target-repo or organization/*):" @target_repo = gets.chomp puts "Delete labels in target repo with 0 issues? (y/n)" @clear_labels = gets.chomp @source_labels = @client.labels(@source_repo) @source_labels = Hash[@source_labels.map {|l| [l.name, l.color]}] @target_repo.include?("*") ? copy_to_all_repos() : add_source_labels() end