class Dug::Runner
Attributes
servicer[R]
Public Class Methods
new()
click to toggle source
# File lib/dug/runner.rb, line 11 def initialize @servicer = Dug::GmailServicer.new servicer.authorize! end
run(*args)
click to toggle source
# File lib/dug/runner.rb, line 7 def self.run(*args) new.run(*args) end
Public Instance Methods
run()
click to toggle source
# File lib/dug/runner.rb, line 16 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 Instance Methods
unprocessed_notifications(use_cache: true)
click to toggle source
# File lib/dug/runner.rb, line 30 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
unprocessed_notifications?()
click to toggle source
# File lib/dug/runner.rb, line 50 def unprocessed_notifications? !!unprocessed_notifications(use_cache: false) end