Sha256: f73195a34eb6e02dbe7448a304a3606b66cc6cd29a7f643050ca0ae2673a5444

Contents?: true

Size: 1.8 KB

Versions: 5

Compression:

Stored size: 1.8 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_all_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

5 entries across 5 versions & 1 rubygems

Version Path
dri-0.10.2 lib/dri/commands/rm/emoji.rb
dri-0.10.1 lib/dri/commands/rm/emoji.rb
dri-0.10.0 lib/dri/commands/rm/emoji.rb
dri-0.9.0 lib/dri/commands/rm/emoji.rb
dri-0.8.0 lib/dri/commands/rm/emoji.rb