-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
42 lines (35 loc) · 1008 Bytes
/
app.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
require 'sinatra'
require 'uri'
require 'net/http'
require 'json'
def pushover_settings
{ user: 'ykvA53kfTZmElFLxnfe69HMyGNK61r',
token: 'aFRF8JJgnB5xmdaK37KLh1VkMMFgW6' }
end
def pushover(message, **args)
push_params = pushover_settings.merge(args).merge(message: message)
uri = URI.parse('https://api.pushover.net/1/messages.json')
Net::HTTP.post_form(uri, push_params)
end
def files_string(files)
files.map{|f| " #{f['file']} (#{f['type']})"}.join("\n")
end
def commit_string(c)
"#{c['timestamp']}\n#{c['author']}@#{c['branch']}(#{c['raw_node'][0,7]})\n#{c['message']}\n" + files_string(c['files'])
end
get '/' do
params.inspect.tap {|x| pushover(x) }
end
post '/' do
params.inspect.tap {|x| pushover(x) }
end
post '/bitbucket' do
data = JSON.parse params['payload']
title = data["repository"]["name"]
if (commits = data["commits"]).empty?
pushover(data.to_s, title: title)
else
commits.each{|c| pushover(commit_string(c), title: title) }
end
''
end