├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | tmp/ 4 | npm-debug.log* 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | node_js: 2 | - "0.12" 3 | - "4" 4 | sudo: false 5 | language: node_js 6 | script: "npm run test:cov" 7 | after_script: "npm i -g codecov.io && cat ./coverage/lcov.info | codecov" 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Yoshua Wuyts 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # github-to-hypercore [![stability][0]][1] 2 | [![npm version][2]][3] [![build status][4]][5] [![test coverage][6]][7] 3 | [![downloads][8]][9] [![js-standard-style][10]][11] 4 | 5 | Stream a github event feed into a hypercore. 6 | 7 | ## Usage 8 | ```sh 9 | $ SECRET= PORT= github-to-hypercore 10 | # => 11 | ``` 12 | 13 | To apply to all of your projects, you need to create a new [github 14 | integration](https://github.com/settings/installations) that can receive the 15 | webhook events. 16 | 17 | ## Installation 18 | ```sh 19 | $ npm install github-to-hypercore 20 | ``` 21 | 22 | ## See Also 23 | - https://developer.github.com/webhooks/#events 24 | - https://github.com/settings/installations 25 | 26 | ## License 27 | [MIT](https://tldrlegal.com/license/mit-license) 28 | 29 | [0]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square 30 | [1]: https://nodejs.org/api/documentation.html#documentation_stability_index 31 | [2]: https://img.shields.io/npm/v/github-to-hypercore.svg?style=flat-square 32 | [3]: https://npmjs.org/package/github-to-hypercore 33 | [4]: https://img.shields.io/travis/yoshuawuyts/github-to-hypercore/master.svg?style=flat-square 34 | [5]: https://travis-ci.org/yoshuawuyts/github-to-hypercore 35 | [6]: https://img.shields.io/codecov/c/github/yoshuawuyts/github-to-hypercore/master.svg?style=flat-square 36 | [7]: https://codecov.io/github/yoshuawuyts/github-to-hypercore 37 | [8]: http://img.shields.io/npm/dm/github-to-hypercore.svg?style=flat-square 38 | [9]: https://npmjs.org/package/github-to-hypercore 39 | [10]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square 40 | [11]: https://github.com/feross/standard 41 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const concat = require('concat-stream') 4 | const listen = require('merry/listen') 5 | const string = require('merry/string') 6 | const notFound = require('merry/404') 7 | const normcore = require('normcore') 8 | const error = require('merry/error') 9 | const Env = require('merry/env') 10 | const crypto = require('crypto') 11 | const merry = require('merry') 12 | const pump = require('pump') 13 | 14 | const env = Env({ 15 | PORT: 8080, 16 | SECRET: String 17 | }) 18 | const app = merry() 19 | 20 | const feed = normcore('github-to-hypercore') 21 | const key = feed.key.toString('hex') 22 | 23 | console.info(JSON.stringify({ key: key })) 24 | 25 | app.router([ 26 | ['/404', notFound()], 27 | [ '/heartbeat', function (req, res, params, done) { 28 | done(null, string('{message: "done"}')) 29 | } ], 30 | ['/', { 31 | post: function (req, res, params, done) { 32 | // handle ping events to check if the service is alive 33 | if (req.headers['x-github-event'] === 'ping') { 34 | done(null, string('{message: "done"}')) 35 | } 36 | 37 | const sigHeader = req.headers['x-hub-signature'] 38 | pump(req, concat(concatSink), function (err) { 39 | if (err) return done(error(500, 'pipe error')) 40 | }) 41 | 42 | function concatSink (buf) { 43 | const hmac = crypto.createHmac('sha1', env.SECRET) 44 | hmac.update(buf) 45 | const signature = ('sha1=' + hmac.digest('hex')) 46 | 47 | if (signature !== sigHeader) { 48 | return done(error(400, 'invalid x-hub-signature')) 49 | } 50 | 51 | feed.append(JSON.stringify({ 52 | headers: req.headers, 53 | body: buf.toString('utf8') 54 | })) 55 | done(null, string('{message: "done"}')) 56 | } 57 | } 58 | }] 59 | ]) 60 | 61 | listen(env.PORT, app.start()) 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-to-hypercore", 3 | "version": "1.1.0", 4 | "description": "Stream a github event feed into a hypercore", 5 | "main": "index.js", 6 | "bin": { 7 | "github-to-hypercore": "index.js" 8 | }, 9 | "scripts": { 10 | "start": "node ./index.js | merry-pretty", 11 | "deps": "dependency-check . && dependency-check . --extra --no-dev", 12 | "test": "standard && npm run deps", 13 | "test:cov": "standard && npm run deps" 14 | }, 15 | "repository": "yoshuawuyts/github-to-hypercore", 16 | "keywords": [ 17 | "hypercore", 18 | "hyperdrive", 19 | "github", 20 | "events" 21 | ], 22 | "license": "MIT", 23 | "dependencies": { 24 | "concat-stream": "^1.5.2", 25 | "merry": "^2.1.1", 26 | "normcore": "^1.0.3", 27 | "pump": "^1.0.1" 28 | }, 29 | "devDependencies": { 30 | "dependency-check": "^2.6.0", 31 | "standard": "^8.5.0" 32 | } 33 | } 34 | --------------------------------------------------------------------------------