├── .gitignore ├── .jshintignore ├── .jshintrc ├── LICENSE ├── README.md ├── bin └── githubhook ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .swp 2 | node_modules 3 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | 4 | "curly": true, 5 | "latedef": true, 6 | "quotmark": true, 7 | "undef": true, 8 | "unused": true, 9 | "trailing": true 10 | } 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Programmed by Nathan LaFreniere, Copyright (c) 2012 &Yet 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | node-github-hook 2 | ================ 3 | 4 | This is a very simple, easy to use evented web hook API for GitHub or GitLab. A command-line executable is also available. 5 | 6 | To Install: 7 | ----------- 8 | ``` 9 | npm install githubhook 10 | ``` 11 | 12 | To Use: 13 | ------- 14 | 15 | ```javascript 16 | var githubhook = require('githubhook'); 17 | var github = githubhook({/* options */}); 18 | 19 | github.listen(); 20 | 21 | github.on('*', function (event, repo, ref, data) { 22 | }); 23 | 24 | github.on('event', function (repo, ref, data) { 25 | }); 26 | 27 | github.on('event:reponame', function (ref, data) { 28 | }); 29 | 30 | github.on('event:reponame:ref', function (data) { 31 | }); 32 | 33 | github.on('reponame', function (event, ref, data) { 34 | }); 35 | 36 | github.on('reponame:ref', function (event, data) { 37 | }); 38 | 39 | // GitLab system hooks 40 | github.on('*', function (event, type, data) { 41 | }); 42 | 43 | github.on('type', function (event, data) { 44 | }); 45 | 46 | // if you'd like to programmatically stop listening 47 | // github.stop(); 48 | ``` 49 | 50 | Where 'event' is the event name to listen to (sent by GitHub or Gitlab, typically 'push' or 'system'), 'reponame' is the name of your repo (this one is node-github-hook), 'ref' is the git reference (such as ref/heads/master), and 'type' is the type of system hook. 51 | 52 | Configure a WebHook URL to whereever the server is listening, with a path of ```/github/callback``` and you're done! 53 | 54 | Available options are: 55 | 56 | * **host**: the host to listen on, defaults to '0.0.0.0' 57 | * **port**: the port to listen on, defaults to 3420 58 | * **path**: the path for the GitHub callback, defaults to '/github/callback' 59 | * **wildcard**: if true, the path for the GitHub callback will be considered valid as long as it *starts* with the configured path 60 | * **secret**: if specified, you must use the same secret in your webhook configuration in GitHub. if a secret is specified, but one is not configured in GitHub, the hook will fail. if a secret is *not* specified, but one *is* configured in GitHub, the signature will not be validated and will be assumed to be correct. consider yourself warned. this option can also be a function that takes the following parameters: (request, data, callback). callback is error first and should be passed (err, secret) 61 | * **logger**: an optional instance of a logger that supports the "log" and "error" methods and one parameter for data (like console), default is `console`. 62 | * **https**: Options to pass to nodejs https server. If specified, you must follow documentation about nodejs https library (See options in https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) 63 | * **trustProxy**: By default the `x-forwarded-for` header is trusted when determining the remoteAddress to log for a request. Set this to `false` to disable this behavior 64 | * **enableHealthcheck**: Respond to GET requests with a 204 response for healthcheck purposes 65 | * **healthcheckCode**: Override the 204 status code for healthchecks (for systems that aren't friendly with HTTP spec compliance and want a 200, for example) 66 | 67 | 68 | Command-line 69 | ------------- 70 | 71 | You can use the command-line client to execute a shell script when a particular 72 | event occurs. 73 | 74 | Install it globally: 75 | 76 | ```bash 77 | $ npm install -g githubhook 78 | ``` 79 | 80 | Then you can run `githubhook`: 81 | 82 | ```bash 83 | $ githubhook --help 84 | 85 | Usage: 86 | githubhook [--host=HOST] [--port=PORT] [--callback=URL_PATH] [--secret=SECRET] [--verbose]