-
Notifications
You must be signed in to change notification settings - Fork 1
/
github-notifier.rb
49 lines (45 loc) · 1.51 KB
/
github-notifier.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
49
require 'yaml'
require 'octokit'
require 'shellwords'
require_relative 'conf'
def notify(message:, title: "", subtitle: "", group: nil, open: "")
cmd = [
"./github-notifier.app/Contents/MacOS/github-notifier",
"-appIcon GitHub-Mark-32px.png",
"-message #{message.sub(/^([\[<])/){"\\" + $1}.shellescape}"
]
cmd << "-title #{title.shellescape}" unless title.empty?
cmd << "-subtitle #{subtitle.shellescape}" unless subtitle.empty?
cmd << "-group #{group}" unless group.nil?
cmd << "-open #{open}" unless open.empty?
system cmd.join(" ")
end
YAML.load_file('github.yml').each do |elem|
time = Time.at(Time.new - INTERVAL*60)
begin
Octokit.configure do |c|
c.api_endpoint = elem['API_ENDPOINT']
end
client = Octokit::Client.new(:access_token => elem['ACCESS_TOKEN'])
client.notifications({all: true, since: time.utc.iso8601}).each do |res|
html_url = res[:subject].rels[:latest_comment].get.data[:html_url]
case res[:subject][:type]
when "Issue", "PullRequest"
group = res[:subject].rels[:self].get.data[:id]
when "Commit"
group = res[:subject].rels[:self].get.data[:sha]
end
notify(message: res[:subject][:title],
title: res[:repository][:full_name],
subtitle: res[:subject][:type],
group: group,
open: html_url)
end
rescue => e
#notify(message: e.message, title: "Error")
STDERR.puts Time.now
STDERR.puts e.message
STDERR.puts e.backtrace
exit(false)
end
end