Sha256: 2c4df272e740f42dbf78976c02271e9a3970e9dd1633a09a886125f4c42476c3

Contents?: true

Size: 1.53 KB

Versions: 58

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require "thor"

require_relative "../base"

module Neetob
  class CLI
    module Github
      module Labels
        class Update < Base
          attr_accessor :repos, :sandbox, :old_name, :new_name

          def initialize(repos, old_name, new_name, sandbox = false)
            super()
            @repos = repos
            @sandbox = sandbox
            @old_name = old_name
            @new_name = new_name
          end

          def run
            matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox)
            matching_repos.each do |repo|
              ui.info("\nUpdating label for #{repo} repo \n")
              begin
                update_label!(repo, old_name, new_name)
              rescue Octokit::NotFound
                ui.say("Ignoring update for #{repo} repo as it doesn't have the \"#{old_name}\" label.")
              rescue StandardError => e
                ExceptionHandler.new(e).process
              end
            end
          end

          private

            def update_label!(repo, old_name, new_name)
              client.label(repo, new_name)
              ui.error("Label with name \"#{new_name}\" already exists.")
              nil
            rescue Octokit::NotFound
              client.update_label(repo, old_name, { name: new_name })
              ui.success("Label \"#{old_name}\" updated to \"#{new_name}\" successfully")
            rescue StandardError => e
              ExceptionHandler.new(e).process
            end
        end
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
neetob-0.5.16 lib/neetob/cli/github/labels/update.rb
neetob-0.5.15 lib/neetob/cli/github/labels/update.rb
neetob-0.5.14 lib/neetob/cli/github/labels/update.rb
neetob-0.5.13 lib/neetob/cli/github/labels/update.rb
neetob-0.5.12 lib/neetob/cli/github/labels/update.rb
neetob-0.5.11 lib/neetob/cli/github/labels/update.rb
neetob-0.5.10 lib/neetob/cli/github/labels/update.rb
neetob-0.5.9 lib/neetob/cli/github/labels/update.rb
neetob-0.5.8 lib/neetob/cli/github/labels/update.rb
neetob-0.5.7 lib/neetob/cli/github/labels/update.rb
neetob-0.5.6 lib/neetob/cli/github/labels/update.rb
neetob-0.5.5 lib/neetob/cli/github/labels/update.rb
neetob-0.5.4 lib/neetob/cli/github/labels/update.rb
neetob-0.5.3 lib/neetob/cli/github/labels/update.rb
neetob-0.5.2 lib/neetob/cli/github/labels/update.rb
neetob-0.5.1 lib/neetob/cli/github/labels/update.rb
neetob-0.5.0 lib/neetob/cli/github/labels/update.rb
neetob-0.4.37 lib/neetob/cli/github/labels/update.rb
neetob-0.4.36 lib/neetob/cli/github/labels/update.rb
neetob-0.4.35 lib/neetob/cli/github/labels/update.rb