Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit dc51a68

Browse files
committed
Use same base code as template-github-app
1 parent e642c60 commit dc51a68

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

server.rb

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,13 @@
1010
set :port, 3000
1111
set :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-
3113
class 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
158142
end

template_server.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class GHAapp < Sinatra::Application
4949
# Before each request to the `/event_handler` route
5050
before '/event_handler' do
5151
get_payload_request(request)
52-
verify_webhook_signature
52+
verify_webhook_signature!
5353
authenticate_app
5454
# Authenticate the app installation in order to run API operations
5555
authenticate_installation(@payload)
@@ -143,10 +143,11 @@ def verify_webhook_signature
143143

144144
end
145145

146-
# Finally some logic to let us run this server directly from the commandline, or with Rack
147-
# Don't worry too much about this code. But, for the curious:
146+
# Finally some logic to let us run this server directly from the command line,
147+
# or with Rack. Don't worry too much about this code. But, for the curious:
148148
# $0 is the executed file
149149
# __FILE__ is the current file
150-
# If they are the same—that is, we are running this file directly, call the Sinatra run method
150+
# If they are the same—that is, we are running this file directly, call the
151+
# Sinatra run method
151152
run! if __FILE__ == $0
152153
end

0 commit comments

Comments
 (0)