10
10
set :port , 3000
11
11
set :bind , '0.0.0.0'
12
12
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
-
31
13
class GHAapp < Sinatra ::Application
32
14
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.
34
17
PRIVATE_KEY = OpenSSL ::PKey ::RSA . new ( ENV [ 'GITHUB_PRIVATE_KEY' ] . gsub ( '\n' , "\n " ) )
35
18
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
37
20
# that webhooks are sent by GitHub.
38
21
WEBHOOK_SECRET = ENV [ 'GITHUB_WEBHOOK_SECRET' ]
39
22
@@ -46,10 +29,10 @@ class GHAapp < Sinatra::Application
46
29
end
47
30
48
31
49
- # Before each request to the `/event_handler` route
32
+ # Executed before each request to the `/event_handler` route
50
33
before '/event_handler' do
51
34
get_payload_request ( request )
52
- verify_webhook_signature
35
+ verify_webhook_signature!
53
36
authenticate_app
54
37
# Authenticate the app installation in order to run API operations
55
38
authenticate_installation ( @payload )
@@ -149,10 +132,11 @@ def verify_webhook_signature
149
132
150
133
end
151
134
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:
154
137
# $0 is the executed file
155
138
# __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
157
141
run! if __FILE__ == $0
158
142
end
0 commit comments