Sha256: 5edd48dad60dfd75e39756f3f88605f7dfa94e026e0e47614246c81b7c84acb2

Contents?: true

Size: 1.7 KB

Versions: 1

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

require "thor"

require_relative "../base"

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

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

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

          private

            def update_label!(app, old_name, new_name)
              client.label(app, new_name)
              ui.error("Label with name \"#{new_name}\" already exists.")
              nil
            rescue Octokit::NotFound
              client.update_label(app, 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

1 entries across 1 versions & 1 rubygems

Version Path
neetob-0.2.2 lib/neetob/cli/github/labels/update.rb