Class: CodeReviewNotifier

Inherits:
Rubiclifier::BaseApplication
  • Object
show all
Defined in:
lib/code_review_notifier.rb

Instance Method Summary collapse

Instance Method Details

#data_directoryObject



75
76
77
# File 'lib/code_review_notifier.rb', line 75

def data_directory
  "~/.code_review_notifier"
end

#featuresObject



57
58
59
60
61
62
63
64
# File 'lib/code_review_notifier.rb', line 57

def features
  [
    Rubiclifier::Feature::BACKGROUND,
    Rubiclifier::Feature::DATABASE,
    Rubiclifier::Feature::IDLE_DETECTION,
    Rubiclifier::Feature::NOTIFICATIONS
  ]
end

#is_first_run?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/code_review_notifier.rb', line 83

def is_first_run?
  Rubiclifier::DB.query_single_row("SELECT id FROM code_change_activity_notified;").nil?
end

#migrations_locationObject



79
80
81
# File 'lib/code_review_notifier.rb', line 79

def migrations_location
  "#{File.expand_path(File.dirname(__FILE__) + "/..")}/migrations.rb"
end

#not_setupObject



50
51
52
53
54
55
# File 'lib/code_review_notifier.rb', line 50

def not_setup
  Rubiclifier::Notification.new(
    "Missing Setup Info",
    "Run `code_review_notifier --setup` to setup."
  ).send
end

#run_applicationObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/code_review_notifier.rb', line 21

def run_application
  $stdout.sync = true
  while true
    unless Rubiclifier::IdleDetector.is_idle?
      is_first_run = is_first_run?
      puts
      puts(Time.now().to_s)
      puts("Querying API...")
      all_code_changes = Api.current_api.all_code_changes
      puts("Checking for notifications to display...")
      all_activity = []
      all_code_changes.each do |cc|
        cc.code_change_activity.sort! { |a, b| a.created_at <=> b.created_at }
        all_activity.concat(cc.code_change_activity)
      end
      all_activity.select(&:should_notify?).each do |code_change_activity|
        code_change_activity.notified
        unless is_first_run
          puts("Notifying of change!")
          CodeChangeNotification.new(code_change_activity).send
          sleep(SECONDS_BETWEEN_NOTIFICATIONS)
        end
      end
      puts("Sleeping for #{SECONDS_BETWEEN_RUNS} seconds...")
    end
    sleep(SECONDS_BETWEEN_RUNS)
  end
end

#settingsObject



66
67
68
69
70
71
72
73
# File 'lib/code_review_notifier.rb', line 66

def settings
  @settings ||= [
    Rubiclifier::Setting.new("base_api_url", "base URL", explanation: "e.g. https://gerrit.google.com"),
    Rubiclifier::Setting.new("api_token", "API token"),
    Rubiclifier::Setting.new("username", "Gitlab username"),
    Rubiclifier::Setting.new("team_name", "Gitlab team")
  ]
end

#show_helpObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/code_review_notifier.rb', line 9

def show_help
  puts
  puts("This polls for updates to patch sets/pull requests and notifies you about any relevant changes.")
  puts
  puts("Usage:")
  puts("  code_review_notifier --help  | Shows this help menu")
  puts("  code_review_notifier --setup | Runs setup")
  puts("  code_review_notifier         | Start listening for changes (should be run in background)")
  puts
  exit
end