lib/neetob/cli/github/labels/delete.rb in neetob-0.2.3 vs lib/neetob/cli/github/labels/delete.rb in neetob-0.2.4

- old
+ new

@@ -7,37 +7,42 @@ module Neetob class CLI module Github module Labels class Delete < Base - attr_accessor :repos, :sandbox, :labels, :all_neeto_repos + attr_accessor :repos, :sandbox, :labels - def initialize(repos, labels, sandbox = false, all_neeto_repos = false) + def initialize(repos, labels, sandbox = false) super() @labels = labels @repos = repos @sandbox = sandbox - @all_neeto_repos = all_neeto_repos end def run - check_for_apps_and_all_neeto_repos_option(repos, all_neeto_repos) - matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox, false, all_neeto_repos) + matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox) matching_repos.each do |repo| - ui.info("\n Deleting labels from #{repo} repo \n") + ui.info("\nDeleting labels from #{repo} repo \n") labels.each do |label| - delete_label(repo, label) + begin + check_if_label_exist!(repo, label) + delete_label(repo, label) + rescue Octokit::NotFound + ui.say(" ↳The repo doesn't have the label \"#{label}\"") + end end end end private + def check_if_label_exist!(repo, label) + client.label(repo, label) + end + def delete_label(repo, label) if client.delete_label!(repo, label) - ui.success("The \"#{label}\" label deleted successfully") - else - ui.error("The \"#{label}\" label can't be deleted. Please check and try again") + ui.success(" ↳The \"#{label}\" label deleted successfully") end end end end end