-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.rb
52 lines (43 loc) · 1.22 KB
/
web.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
50
51
52
# Bunto Announce Bot
require 'erb'
require 'json'
require 'mustache'
require 'sinatra'
require 'twitter'
use Rack::Auth::Basic, "Restricted" do |username, password|
username == ENV['BASIC_USERNAME'] and password == ENV['BASIC_PASSWORD']
end
class GithubTwitter
def initialize(payload)
payload = JSON.parse(payload)
return unless payload.keys.include?("repository")
return unless payload["ref"].include?("tags")
return unless payload["before"].include?("0000000000000000000000000")
repo = payload["repository"]["name"]
payload['tag'] = payload["ref"][10..-1]
template = "New {{ name }} release: {{ tag }} - #BuntoWAF {{ url }}"
connect(repo).update(
Mustache.render(
template,
:name => payload['repository']['name'],
:tag => payload['tag'],
:url => payload['repository']['url']
)
)
end
def connect(repo)
return Twitter::Client.new(
:oauth_token => ENV['TWITTER_TOKEN'],
:oauth_token_secret => ENV['TWITTER_TOKEN_SECRET'],
:consumer_key => ENV['TWITTER_CONSUMER_KEY'],
:consumer_secret => ENV['TWITTER_CONSUMER_SECRET']
)
end
end
get '/ping' do
"Pong"
end
post '/hook' do
GithubTwitter.new(params[:payload])
"200"
end