This repository has been archived by the owner on May 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f5b40fb
Showing
13 changed files
with
410 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "./config/environment" | ||
run Rack::URLMap.new("/" => EventApi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
; EditorConfig is awesome: http://EditorConfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
max_line_length = 80 | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
*.gem | ||
*.rbc | ||
/.config | ||
/coverage/ | ||
/InstalledFiles | ||
/pkg/ | ||
/spec/reports/ | ||
/spec/examples.txt | ||
/test/tmp/ | ||
/test/version_tmp/ | ||
/tmp/ | ||
|
||
# Used by dotenv library to load environment variables. | ||
# .env | ||
|
||
# Ignore Byebug command history file. | ||
.byebug_history | ||
|
||
## Specific to RubyMotion: | ||
.dat* | ||
.repl_history | ||
build/ | ||
*.bridgesupport | ||
build-iPhoneOS/ | ||
build-iPhoneSimulator/ | ||
|
||
## Specific to RubyMotion (use of CocoaPods): | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
# vendor/Pods/ | ||
|
||
## Documentation cache and generated files: | ||
/.yardoc/ | ||
/_yardoc/ | ||
/doc/ | ||
/rdoc/ | ||
|
||
## Environment normalization: | ||
/.bundle/ | ||
/vendor/bundle | ||
/lib/bundler/man/ | ||
|
||
# for a library or gem, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# Gemfile.lock | ||
# .ruby-version | ||
# .ruby-gemset | ||
|
||
# Used by RuboCop. Remote config files pulled in from inherit_from directive. | ||
# .rubocop-https?--* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.7.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"recommendations": [ | ||
"EditorConfig.editorconfig", | ||
"shd101wyy.markdown-preview-enhanced", | ||
"DavidAnson.vscode-markdownlint", | ||
"dbaeumer.vscode-eslint", | ||
"esbenp.prettier-vscode", | ||
"formulahendry.auto-close-tag", | ||
"formulahendry.auto-rename-tag", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true, | ||
}, | ||
"editor.formatOnSave": false, | ||
"editor.rulers": [80, 120], | ||
"prettier.semi": false, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[json]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[markdown]": { | ||
"files.trimTrailingWhitespace": false | ||
}, | ||
"eslint.validate": ["html", "javascript"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
source "https://rubygems.org" | ||
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | ||
|
||
gem "sinatra" | ||
|
||
group :test do | ||
gem "rspec" | ||
gem "rack-test" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.4.4) | ||
mustermann (1.1.1) | ||
ruby2_keywords (~> 0.0.1) | ||
rack (2.2.3) | ||
rack-protection (2.1.0) | ||
rack | ||
rack-test (1.1.0) | ||
rack (>= 1.0, < 3) | ||
rspec (3.10.0) | ||
rspec-core (~> 3.10.0) | ||
rspec-expectations (~> 3.10.0) | ||
rspec-mocks (~> 3.10.0) | ||
rspec-core (3.10.1) | ||
rspec-support (~> 3.10.0) | ||
rspec-expectations (3.10.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.10.0) | ||
rspec-mocks (3.10.2) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.10.0) | ||
rspec-support (3.10.2) | ||
ruby2_keywords (0.0.4) | ||
sinatra (2.1.0) | ||
mustermann (~> 1.0) | ||
rack (~> 2.2) | ||
rack-protection (= 2.1.0) | ||
tilt (~> 2.0) | ||
tilt (2.0.10) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
rack-test | ||
rspec | ||
sinatra | ||
|
||
BUNDLED WITH | ||
2.1.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Jason Miller | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Github Event Server | ||
|
||
Simple server used to processing events posted by [Github Web-hooks]. | ||
|
||
This tool is developed in Ruby with the light-weight [Sinatra] framework. | ||
|
||
Testing is facilitated with RSpec / [RSpec-Sinatra] | ||
|
||
## Resources | ||
|
||
* [A Simple Sinatra App to Receive Github Webhook Payload] | ||
* [How to use Bundler with Ruby] | ||
* [Sinatra Applications with Rspec] | ||
* [Testing Sinatra with Rack::Test] | ||
|
||
[Github Web-hooks]: https://docs.github.com/en/developers/webhooks-and-events/webhooks | ||
[Sinatra]: http://sinatrarb.com/documentation.html | ||
[RSpec-Sinatra]: https://github.com/tansaku/rspec-sinatra | ||
[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/ | ||
[How to use Bundler with Ruby]: https://bundler.io/v2.2/guides/bundler_setup.html | ||
[Sinatra Applications with Rspec]: http://www.shiroyasha.io/sinatra-app-with-rspec.html | ||
[Testing Sinatra with Rack::Test]: http://sinatrarb.com/testing.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class EventApi < Sinatra::Base | ||
|
||
end | ||
|
||
|
||
|
||
|
||
set :port, 5000 | ||
|
||
post '/' do | ||
event = request.env['HTTP_X_GITHUB_EVENT'] | ||
case event | ||
when 'push' | ||
payload_body = request.body.read | ||
verify_signature(payload_body) | ||
payload = JSON.parse(request.body.read) | ||
|
||
repo = payload['repository']['full_name'] | ||
user = payload['sender']['login'] | ||
user_url = payload['sender']['html_url'] | ||
puts "This is a watch event on '#{repo}' by '#{user}': #{user_url}" | ||
|
||
else | ||
puts "Received '#{event}' type event, which is not currently supported" | ||
end | ||
end | ||
|
||
def verify_signature(payload_body) | ||
puts "ENV['SECRET_TOKEN']: #{ENV['SECRET_TOKEN'].inspect}" | ||
signature = 'sha256=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), ENV['SECRET_TOKEN'], payload_body) | ||
return halt 500, "Signatures didn't match!" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_HUB_SIGNATURE_256']) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "rubygems" | ||
require "bundler" | ||
Bundler.require(:default) # load all the default gems | ||
Bundler.require(Sinatra::Base.environment) # load all the environment specific gems | ||
require "active_support/deprecation" | ||
require "active_support/all" |
Oops, something went wrong.