1010set :port , 3000
1111set :bind , '0.0.0.0'
1212
13-
14- # This is template code to create a GitHub App server.
15- # You can read more about GitHub Apps here: # https://developer.github.com/apps/
16- #
17- # On its own, this app does absolutely nothing, except that it can be installed.
18- # It's up to you to add functionality!
19- # You can check out one example in advanced_server.rb.
20- #
21- # This code is a Sinatra app, for two reasons:
22- # 1. Because the app will require a landing page for installation.
23- # 2. To easily handle webhook events.
24- #
25- # Of course, not all apps need to receive and process events!
26- # Feel free to rip out the event handling code if you don't need it.
27- #
28- # Have fun!
29- #
30-
3113class GHAapp < Sinatra ::Application
3214
33- # Expects that the private key in PEM format. Converts the newlines
15+ # Converts the newlines. Expects that the private key has been set as an
16+ # environment variable in PEM format.
3417 PRIVATE_KEY = OpenSSL ::PKey ::RSA . new ( ENV [ 'GITHUB_PRIVATE_KEY' ] . gsub ( '\n' , "\n " ) )
3518
36- # Your registered app must have a secret set. The secret is used to verify
19+ # Your registered app must set have a secret set. The secret is used to verify
3720 # that webhooks are sent by GitHub.
3821 WEBHOOK_SECRET = ENV [ 'GITHUB_WEBHOOK_SECRET' ]
3922
@@ -46,10 +29,10 @@ class GHAapp < Sinatra::Application
4629 end
4730
4831
49- # Before each request to the `/event_handler` route
32+ # Executed before each request to the `/event_handler` route
5033 before '/event_handler' do
5134 get_payload_request ( request )
52- verify_webhook_signature
35+ verify_webhook_signature!
5336 authenticate_app
5437 # Authenticate the app installation in order to run API operations
5538 authenticate_installation ( @payload )
@@ -149,10 +132,11 @@ def verify_webhook_signature
149132
150133 end
151134
152- # Finally some logic to let us run this server directly from the commandline, or with Rack
153- # Don't worry too much about this code. But, for the curious:
135+ # Finally some logic to let us run this server directly from the command line,
136+ # or with Rack. Don't worry too much about this code. But, for the curious:
154137 # $0 is the executed file
155138 # __FILE__ is the current file
156- # If they are the same—that is, we are running this file directly, call the Sinatra run method
139+ # If they are the same—that is, we are running this file directly, call the
140+ # Sinatra run method
157141 run! if __FILE__ == $0
158142end
0 commit comments