Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #44 from plunchete/master
Browse files Browse the repository at this point in the history
Middleware to transform data from Github's webhook and send it to Keen IO
  • Loading branch information
mikz committed May 31, 2017
2 parents 3eb14a5 + 8248868 commit e7b54f6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
31 changes: 31 additions & 0 deletions middleware/github-webhook-keen/README.md
@@ -0,0 +1,31 @@
Send all the activity in your Github repo to Keen IO
----



Overview
----
Keen IO allows you to gather data from different places and consume it in a very easy way using their APIs. This middleware modifies the data provided from Github and send it to Keen IO.



Requirements
----
* A [Keen IO](https://keen.io/) account
* An [APItools](https://www.apitools.com/) account



How to use it
----

1. Set up a new monitor and point it to Keen IO (`https://api.keen.io/v3/`)
2. Go to the 'Pipeline' tab in your APITools monitor and add enable this middleware
3. Edit the middleware and substitute `YOUR-WRITE-KEEN-IO-TOKEN-HERE` with your write token from Keen IO
4. Go to your repo on Github and click on Settings >> Webhooks & Services >> Add webhook
![Add webhook screenshot](http://i.imgur.com/36JDgE9.png)
5. Configure the webhook
* Add your APItools URL followed by the Keen IO project that you want to use. E.g `https://APItools_MONITOR_URL.my.apitools.com/projects/KEEN_IO_PROJECT_ID` **NOTE** Notice that you don't have to put v3 here but in the monitor
* Select the events that you want to send. E.g `Send me everything.`
7. If everything went well, you should see all the new events from your repo in your project on Keen IO
* The first event after you set up your webhook is a `ping` event
12 changes: 12 additions & 0 deletions middleware/github-webhook-keen/apitools.json
@@ -0,0 +1,12 @@

{
"name": "Github webhooks to Keen IO",
"description": "Send all the activity in your Github repo to Keen IO",
"files": ["github-webhook-keen-io.lua"],
"author" : "plunchete",
"email" : "plunchete@gmail.com",
"github_user" : "plunchete",
"version" : "1.0.0",
"categories" : ["data", "keen_IO", "github"],
"endpoints": ["https://api.keen.io/3.0/"]
}
26 changes: 26 additions & 0 deletions middleware/github-webhook-keen/github-webhook-keen-io.lua
@@ -0,0 +1,26 @@
return function(request, next_middleware)

local keen_write_token = "YOUR-WRITE-KEEN-IO-TOKEN-HERE"

-- We want to modify the url by:
-- #1 Adding the header X-GitHub-Event as name of the event
-- #2 Add api_key
local uri = request.uri

-- if the url doesn't end with / add it
if string.sub(uri,-string.len("/")) ~= "/" then
uri = uri .. "/"
end

-- adding event to the url
uri = uri .. "events/" .. request.headers["X-GitHub-Event"]

-- adding the write token
uri = uri .. '?api_key=' .. keen_write_token

-- swap urls
request.uri = uri

local response = next_middleware()
return response
end

0 comments on commit e7b54f6

Please sign in to comment.