Octo Events is an application that listens to Github Events via webhooks and exposes an api for later use.
All you need to run Octo Events is Docker installed with docker-compose.
- To install Docker follow the instructions here;
- Validate that you have docker compose installed and running:
$ docker-compose --version
# docker-compose version 1.28.5, build c4eb3a1f
We need a github test repository to validate that events triggers the webhook.
- Login to your github account;
- Create a new repository with a README;
- Keep track of the test repository name, it will be needed later.
- Clone this project:
$ git clone https://github.com/ricardoebbers/octo_events.git
- Change into repository directory:
$ cd octo_events
- Create the api, database and ngrok with docker-compose:
$ docker-compose up -d
# Creating network "octo_events_default" with the default driver
# Creating octo_events_db_1 ... done
# Creating octo_events_api_1 ... done
# Creating octo_events_ngrok_1 ... done
- Go to the ngrok web interface at http://localhost:4551
- Take note of the generated tunnel url:
- Create a new webhook for your test repository at
https://github.com/<your_github_username>/<your_test_repository>/settings/hooks/new
(you might need to confirm your github access, as you will be entering sudo mode) - On "payload URL" insert the generated tunnel url from ngrok, with the
/payload
suffix like this:http://<ngrok_tunnel_url>/payload
; - On "Content type" select "application/json";
- You can keep the "secret key" blank for now;
- Check the "let me select individual events" radio button;
- Check the "Issues" checkbox and uncheck "Pushes" checkbox;
- Keep the "Active" checkbox checked;
- Click on "Add Webhook" button;
- Github sends a
ping
event when webhooks are created. On the Recent Deliveries section you should see an uuid with a green checkmark like this:
We should be all set up, so now we can test the service.
You can run all tests by using docker and mix, with the server running:
$ docker exec octo_events_api mix test --cover
- Go to the test repository and create a new issue
https://github.com/<your_github_username>/<your_test_repository>/issues/new
; - Check http://localhost:4551. You should see something like this:
The
POST /payload 200 OK
is from theping
event, and thePOST /payload 201 Created
is from theissue opened
event
- Edit your webhook to send unhandled events like
pull requests
; - Create a pull request. You can edit the README file on the browser for simplicity.
- Check http://localhost:4551 again, you should see:
The event payloads are relatively big. Considering that, I recommend using a REST client like Insomnia or Postman to make it easier to read, but you can use your browser too.
- Call GET
http://localhost:4000/issues
to see a list of issue ids that have events registered for them; - Pick one of the ids from the list and call GET
http://localhost:4000/issues/<issue_id>/events
to see all events for that issue.
Don't forget to stop and remove the containers:
$ docker-compose down --volumes --rmi local