forked from juliancheal/cp-8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
48 lines (35 loc) · 946 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
43
44
45
46
47
48
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "bundler"
Bundler.require :default, ENV["RACK_ENV"].to_sym
require "cp8"
require "github_authentication"
set :show_exceptions, false
post "/payload" do
Cp8.github_client = authenticated_github_client
Processor.new(payload, config: config).process
end
error 500 do
error = env["sinatra.error"]
"#{error.class}: #{error.message}"
end
private
CP8_CONFIG_FILE = ".cp8.yml"
def authenticated_github_client
GithubAuthentication.new(payload).client
end
def payload
request.body.rewind
Payload.new_from_json(request.body.read)
end
def config
fetch_config || {}
end
def fetch_config
YAML.load config_file_contents
rescue TypeError
end
def config_file_contents
Base64.decode64 Cp8.github_client.contents(payload.repo, path: CP8_CONFIG_FILE).content
rescue Octokit::NotFound
end