Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/doowb/is-valid-github-event
Validate GitHub webhook events.
https://github.com/doowb/is-valid-github-event
cloud-functions express github github-events webhook
Last synced: about 1 month ago
JSON representation
Validate GitHub webhook events.
- Host: GitHub
- URL: https://github.com/doowb/is-valid-github-event
- Owner: doowb
- License: mit
- Created: 2017-05-19T04:00:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-19T04:01:17.000Z (over 7 years ago)
- Last Synced: 2024-11-25T03:15:11.972Z (about 2 months ago)
- Topics: cloud-functions, express, github, github-events, webhook
- Language: JavaScript
- Homepage: https://doowb.com
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# is-valid-github-event [![NPM version](https://img.shields.io/npm/v/is-valid-github-event.svg?style=flat)](https://www.npmjs.com/package/is-valid-github-event) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-valid-github-event.svg?style=flat)](https://npmjs.org/package/is-valid-github-event) [![NPM total downloads](https://img.shields.io/npm/dt/is-valid-github-event.svg?style=flat)](https://npmjs.org/package/is-valid-github-event) [![Linux Build Status](https://img.shields.io/travis/doowb/is-valid-github-event.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/is-valid-github-event)
> Validate GitHub webhook events.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save is-valid-github-event
```Install with [yarn](https://yarnpkg.com):
```sh
$ yarn add is-valid-github-event
```## Usage
```js
var isValid = require('is-valid-github-event');
```## API
### [.isValid](index.js#L34)
Validates that the provided request is a valid GitHub webhook request with a valid GitHub event and action.
**Params**
* `req` **{Object}**: Instance of an HTTP Request object (usually from express, hapi, or koa)
* `secret` **{String}**: Optional secret used to sign the GitHub request. Leave this out to just check `event` or `action`
* `options` **{Object}**: Additional options for validating against `event` and `action`.
* `options.event` **{String}**: The GitHub event to validate against. See [typeof-github-event](https://github.com/doowb/typeof-github-event) for more information.
* `options.action` **{String}**: The event action to validate against. See [GitHub API docs](https://developer.github.com/v3/activity/events/types/) for more information.
* `returns` **{Boolean}**: Returns `true` when valid and `false` when not.**Example**
```js
// using an express middleware
express.post('/webhook', function(req, res) {
if (!isValid(req, 'my-secret', {event: 'issues', action: 'opened'})) {
res.status(500);
res.send({message: 'Invalid request'});
return;
}
res.status(200);
res.send({message: 'Valid request'});
})
```## About
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.
### Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```### Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```### Author
**Brian woodward**
* [github/doowb](https://github.com/doowb)
* [twitter/doowb](https://twitter.com/doowb)### License
Copyright © 2017, [Brian woodward](https://doowb.com).
Released under the [MIT License](LICENSE).***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 18, 2017._