Sha256: 32eb7bfa0bd474bdba6a6f02ab070a89812b932f5eae0fc1280c33b4723b0e30

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

require_relative '../../command'

module Dri
  module Commands
    class Rm
      class Emoji < Dri::Command
        def initialize(options)
          @options = options
        end

        def execute(input: $stdin, output: $stdout) # rubocop:disable Metrics/AbcSize
          verify_config_exists

          remove = prompt.yes? "Are you sure you want to remove all #{emoji} award emojis from issues?"

          unless remove
            logger.info "Emojis kept in place 👍"
            exit 0
          end

          logger.info "Removing #{emoji} emoji from issues..."

          spinner.start

          failures_with_award_emoji = api_client.fetch_triaged_failures(emoji: emoji, state: 'opened')
          incidents_with_award_emoji = api_client.fetch_triaged_incidents(emoji: emoji)

          issues_with_award_emoji = failures_with_award_emoji + incidents_with_award_emoji

          spinner.stop

          cleared_issues_counter = 0
          issues_with_award_emoji.each do |issue|
            logger.info "Removing #{emoji} emoji from #{issue.web_url}"

            response = api_client.fetch_awarded_emojis(issue.iid, project_id: issue.project_id)
            emoji_found = response.find { |e| e.name == emoji && e.to_h.dig('user', 'username') == username }

            if emoji_found.nil?
              logger.error "Emoji #{add_color(emoji, :red)} not found for username: #{add_color(username, :red)}"
              next
            else
              api_client.delete_award_emoji(issue.iid, emoji_id: emoji_found.id, project_id: issue.project_id)
              cleared_issues_counter += 1
            end
          end

          output.puts "Done! ✅"
          logger.success "Removed #{emoji} from #{cleared_issues_counter} issue(s)."
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dri-0.7.0 lib/dri/commands/rm/emoji.rb