<commit_before>module Dug
  class Runner
    include Dug::Logger

    attr_reader :servicer

    def self.run(*args)
      new.run(*args)
    end

    def initialize
      @servicer = Dug::GmailServicer.new
      servicer.authorize!
    end

    def run
      if unprocessed_notifications?
        log("Processing #{unprocessed_notifications.size} GitHub notifications...")
        unprocessed_notifications.each do |message|
          Dug::MessageProcessor.new(message.id, servicer).execute
        end
        log("Finished processing #{unprocessed_notifications.size} GitHub notifications.")
      else
        log("No new GitHub notifications.")
      end
    end

    private

    def unprocessed_notifications(use_cache: true)
      unless use_cache
        log("Requesting latest emails from Gmail...")
        @unprocessed_notifications = nil
      end
      unprocessed_label = servicer.labels(use_cache: use_cache)[Dug.configuration.unprocessed_label_name]

      # The reverse! is required because we want to process messages in order
      # and Google doesn't allow you to sort by anything because labels. Order
      # is required here to account for state changes like reopened issues
      @unprocessed_notifications ||=
        begin
          messages = servicer
            .list_user_messages('me', label_ids: [unprocessed_label.id])
            .messages
          messages.reverse! if messages
        end
    end

    def unprocessed_notifications?
      !!unprocessed_notifications(use_cache: false)
    end
  end<commit_msg>error out if the unproccessed label is not found on gmail<commit_after>module Dug
  class Runner
    include Dug::Logger

    attr_reader :servicer

    def self.run(*args)
      new.run(*args)
    end

    def initialize
      @servicer = Dug::GmailServicer.new
      servicer.authorize!
    end

    def run
      if unprocessed_notifications?
        log("Processing #{unprocessed_notifications.size} GitHub notifications...")
        unprocessed_notifications.each do |message|
          Dug::MessageProcessor.new(message.id, servicer).execute
        end
        log("Finished processing #{unprocessed_notifications.size} GitHub notifications.")
      else
        log("No new GitHub notifications.")
      end
    end

    private

    def unprocessed_notifications(use_cache: true)
      unless use_cache
        log("Requesting latest emails from Gmail...")
        @unprocessed_notifications = nil
      end
      unprocessed_label = servicer.labels(use_cache: use_cache)[Dug.configuration.unprocessed_label_name]
      raise "Create the label '#{Dug.configuration.unprocessed_label_name}' on gmail" unless unprocessed_label

      # The reverse! is required because we want to process messages in order
      # and Google doesn't allow you to sort by anything because labels. Order
      # is required here to account for state changes like reopened issues
      @unprocessed_notifications ||=
        begin
          messages = servicer
            .list_user_messages('me', label_ids: [unprocessed_label.id])
            .messages
          messages.reverse! if messages
        end
    end

    def unprocessed_notifications?
      !!unprocessed_notifications(use_cache: false)
    end
  end
{'fraction_non_alphanumeric': 0.06978173993237012, 'fraction_numerical': 0.0, 'mean_word_length': 2.731651376146789, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2923872', 'n_tokens_mistral': 909, 'n_tokens_neox': 850, 'n_words': 248}