Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 17, 2023. It is now read-only.

Commit f5b40fb

Browse filesBrowse files
committed
Initial commit
0 parents  commit f5b40fb
Copy full SHA for f5b40fb

13 files changed

+410
-0
lines changed

‎.config.ru

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "./config/environment"
2+
run Rack::URLMap.new("/" => EventApi)

‎.editorconfig

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; EditorConfig is awesome: http://EditorConfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
indent_style = space
9+
indent_size = 2
10+
trim_trailing_whitespace = true
11+
12+
[*.md]
13+
max_line_length = 80
14+
trim_trailing_whitespace = false

‎.gitignore

Copy file name to clipboard
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
*.gem
2+
*.rbc
3+
/.config
4+
/coverage/
5+
/InstalledFiles
6+
/pkg/
7+
/spec/reports/
8+
/spec/examples.txt
9+
/test/tmp/
10+
/test/version_tmp/
11+
/tmp/
12+
13+
# Used by dotenv library to load environment variables.
14+
# .env
15+
16+
# Ignore Byebug command history file.
17+
.byebug_history
18+
19+
## Specific to RubyMotion:
20+
.dat*
21+
.repl_history
22+
build/
23+
*.bridgesupport
24+
build-iPhoneOS/
25+
build-iPhoneSimulator/
26+
27+
## Specific to RubyMotion (use of CocoaPods):
28+
#
29+
# We recommend against adding the Pods directory to your .gitignore. However
30+
# you should judge for yourself, the pros and cons are mentioned at:
31+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32+
#
33+
# vendor/Pods/
34+
35+
## Documentation cache and generated files:
36+
/.yardoc/
37+
/_yardoc/
38+
/doc/
39+
/rdoc/
40+
41+
## Environment normalization:
42+
/.bundle/
43+
/vendor/bundle
44+
/lib/bundler/man/
45+
46+
# for a library or gem, you might want to ignore these files since the code is
47+
# intended to run in multiple environments; otherwise, check them in:
48+
# Gemfile.lock
49+
# .ruby-version
50+
# .ruby-gemset
51+
52+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
53+
# .rubocop-https?--*

‎.ruby-version

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.7.3

‎.vscode/extensions.json

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"recommendations": [
3+
"EditorConfig.editorconfig",
4+
"shd101wyy.markdown-preview-enhanced",
5+
"DavidAnson.vscode-markdownlint",
6+
"dbaeumer.vscode-eslint",
7+
"esbenp.prettier-vscode",
8+
"formulahendry.auto-close-tag",
9+
"formulahendry.auto-rename-tag",
10+
]
11+
}

‎.vscode/settings.json

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": true,
4+
},
5+
"editor.formatOnSave": false,
6+
"editor.rulers": [80, 120],
7+
"prettier.semi": false,
8+
"[javascript]": {
9+
"editor.defaultFormatter": "esbenp.prettier-vscode"
10+
},
11+
"[json]": {
12+
"editor.defaultFormatter": "esbenp.prettier-vscode"
13+
},
14+
"[markdown]": {
15+
"files.trimTrailingWhitespace": false
16+
},
17+
"eslint.validate": ["html", "javascript"],
18+
}

‎Gemfile

Copy file name to clipboard
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
source "https://rubygems.org"
2+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3+
4+
gem "sinatra"
5+
6+
group :test do
7+
gem "rspec"
8+
gem "rack-test"
9+
end

‎Gemfile.lock

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
diff-lcs (1.4.4)
5+
mustermann (1.1.1)
6+
ruby2_keywords (~> 0.0.1)
7+
rack (2.2.3)
8+
rack-protection (2.1.0)
9+
rack
10+
rack-test (1.1.0)
11+
rack (>= 1.0, < 3)
12+
rspec (3.10.0)
13+
rspec-core (~> 3.10.0)
14+
rspec-expectations (~> 3.10.0)
15+
rspec-mocks (~> 3.10.0)
16+
rspec-core (3.10.1)
17+
rspec-support (~> 3.10.0)
18+
rspec-expectations (3.10.1)
19+
diff-lcs (>= 1.2.0, < 2.0)
20+
rspec-support (~> 3.10.0)
21+
rspec-mocks (3.10.2)
22+
diff-lcs (>= 1.2.0, < 2.0)
23+
rspec-support (~> 3.10.0)
24+
rspec-support (3.10.2)
25+
ruby2_keywords (0.0.4)
26+
sinatra (2.1.0)
27+
mustermann (~> 1.0)
28+
rack (~> 2.2)
29+
rack-protection (= 2.1.0)
30+
tilt (~> 2.0)
31+
tilt (2.0.10)
32+
33+
PLATFORMS
34+
ruby
35+
36+
DEPENDENCIES
37+
rack-test
38+
rspec
39+
sinatra
40+
41+
BUNDLED WITH
42+
2.1.4

‎LICENSE

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Jason Miller
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

Copy file name to clipboard
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Github Event Server
2+
3+
Simple server used to processing events posted by [Github Web-hooks].
4+
5+
This tool is developed in Ruby with the light-weight [Sinatra] framework.
6+
7+
Testing is facilitated with RSpec / [RSpec-Sinatra]
8+
9+
## Resources
10+
11+
* [A Simple Sinatra App to Receive Github Webhook Payload]
12+
* [How to use Bundler with Ruby]
13+
* [Sinatra Applications with Rspec]
14+
* [Testing Sinatra with Rack::Test]
15+
16+
[Github Web-hooks]: https://docs.github.com/en/developers/webhooks-and-events/webhooks
17+
[Sinatra]: http://sinatrarb.com/documentation.html
18+
[RSpec-Sinatra]: https://github.com/tansaku/rspec-sinatra
19+
[A Simple Sinatra App to Receive Github Webhook Payload]: https://blog.arangamani.net/blog/2014/04/16/a-simple-sinatra-app-to-receive-github-webhook-payload/
20+
[How to use Bundler with Ruby]: https://bundler.io/v2.2/guides/bundler_setup.html
21+
[Sinatra Applications with Rspec]: http://www.shiroyasha.io/sinatra-app-with-rspec.html
22+
[Testing Sinatra with Rack::Test]: http://sinatrarb.com/testing.html

‎app/event_api.rb

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class EventApi < Sinatra::Base
2+
3+
end
4+
5+
6+
7+
8+
set :port, 5000
9+
10+
post '/' do
11+
event = request.env['HTTP_X_GITHUB_EVENT']
12+
case event
13+
when 'push'
14+
payload_body = request.body.read
15+
verify_signature(payload_body)
16+
payload = JSON.parse(request.body.read)
17+
18+
repo = payload['repository']['full_name']
19+
user = payload['sender']['login']
20+
user_url = payload['sender']['html_url']
21+
puts "This is a watch event on '#{repo}' by '#{user}': #{user_url}"
22+
23+
else
24+
puts "Received '#{event}' type event, which is not currently supported"
25+
end
26+
end
27+
28+
def verify_signature(payload_body)
29+
puts "ENV['SECRET_TOKEN']: #{ENV['SECRET_TOKEN'].inspect}"
30+
signature = 'sha256=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), ENV['SECRET_TOKEN'], payload_body)
31+
return halt 500, "Signatures didn't match!" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE_256'])
32+
end

‎config/environment.rb

Copy file name to clipboard
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "rubygems"
2+
require "bundler"
3+
Bundler.require(:default) # load all the default gems
4+
Bundler.require(Sinatra::Base.environment) # load all the environment specific gems
5+
require "active_support/deprecation"
6+
require "active_support/all"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.