/octo-events

Application that listens to Github Events via webhooks and expose by an API for later use.

Primary LanguageRuby

What's Octo Events?

Octo Events is an application that listens to Github Events via webhooks and expose by an api for later use.


Getting Started

  1. Install Ruby at the command prompt if you haven't yet. See: How to install Ruby

  2. Bundle gems at the command prompt.

     $ bundle
    
  3. Configure database [postgresql]

    $ rake db:create
    $ rake db:migrate
    
  4. Set a .env file

     $ cp .env.sample .env
    
  5. 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).

  6. 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

  7. Run your rails app

     $ rails s -p 3000
    
  8. 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




Setting up a webhook to Octo Events.

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?:

  1. Select "Let me select individual events."
  2. 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.



Get events from an issue

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

Runnin specs

    $ rspec spec