Octo Events is an application that listens to Github Events via webhooks and expose by an api for later use.
-
Install Ruby at the command prompt if you haven't yet. See: How to install Ruby
-
Bundle gems at the command prompt.
$ bundle
-
Configure database [postgresql]
$ rake db:create $ rake db:migrate
-
Set a .env file
$ cp .env.sample .env
-
Generate an
API_TOKEN
and set it to your.env
file.A random string with high entropy (e.g., by taking the output of
ruby -rsecurerandom -e 'puts SecureRandom.hex(20)'
at the terminal). -
Generate a
SECRET_TOKEN
and set it to your.env
file and also to the GitHub repository you want to integrate with Octo Events. See: How to set your secret token to github⚠️ Important: SECRET_TOKEN on .env must be the same on your github project -
Run your rails app
$ rails s -p 3000
-
Create a ngrok tunel to expose your local development environment to the internet. See Exposing localhost to the internet
$ ./ngrok http 3000
--
🎉🎉 Octo Event is ready to receive webhooks
To set up a webhook, go to the settings page of your repository. From there, click Webhooks, then Add webhook.
Webhooks require a few configuration options before you can make use of them.
Payload URL :
Url generated by your ngrok server followed by webhooks endpoint (/webhooks/v1/events). Ex.: https://d7688d792b10.ngrok.io/webhooks/v1/events
Content Type: Application/json
Secret: Same SECRET_TOKEN
on your .env
file. [Generated on step 6.]
Which events would you like to trigger this webhook?:
- Select "Let me select individual events."
- Check "Issues" option only
Click on 'Add webhooks'
If your app was properly configured you should get a ping event on your Rails log.
Only Issues events are persisted on db by Octo Events.
To list events that was sent to Octo Events by Github webhooks you can send a GET
request to http://localhost:3000/api/v1/issues/:issue_number/events
endpoint.
You can also use your ngrok address if you want. Ex.: https://c2688d792b10.ngrok.io/api/v1/issues/:issue_number/events
Either way you have to send your API_TOKEN
as a token bearer
on request headers to get authenticated.
⚠️ Important: API_TOKEN on .env must be the same on your request header
If you use curl
:
curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" http://localhost:3000/api/v1/issues/:issue_number/events
$ rspec spec