Module: GitlabNotifier

Defined in:
lib/gitlab_notifier/version.rb,
lib/gitlab_notifier.rb

Constant Summary collapse

VERSION =
"0.1.0"
CONFIG_FILE =
"#{ENV['HOME']}/.gitlab_notifier/configs.yml"

Class Method Summary collapse

Class Method Details

.notify(body, title: nil) ⇒ Object



12
13
14
# File 'lib/gitlab_notifier.rb', line 12

def self.notify(body, title: nil)
  TerminalNotifier.notify(body, title: title)
end

.read_rssObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab_notifier.rb', line 16

def self.read_rss
  configs = YAML.load_file(CONFIG_FILE)
  configs['atom'].each do |atom|
    atom_type, atom_address = atom
    atom_last_read = configs['last_read']["#{atom_type}"]
    rss = RSS::Parser.parse(atom_address, false)
    next if !atom_last_read.nil? && rss.updated.content <= atom_last_read
    rss.items.select do |item|
      notify "#{item.title.content}", title: "#{atom_type.capitalize}" if atom_last_read.nil? || item.updated.content > atom_last_read
    end
    configs['last_read']["#{atom_type}"] = rss.updated.content
    File.open(CONFIG_FILE, 'w') { |f| YAML.dump(configs, f) }
  end
end