npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-github-webhook-handler

v0.1.0

Published

Koa.js middleware for processing GitHub Webhooks

Downloads

8

Readme

NPM Version Node.js Version Build status

koa-github-webhook-handler

Koa.js middleware for processing GitHub Webhooks

This library is a small middleware for Koa.js web servers that handles all the logic of receiving and verifying webhook requests from GitHub. It's based on the awesome job of @rvagg here.

Dependency

Any JSON body parser middleware for Koa.js (see complete list here).

Example

import koa from 'koa';
import koaBody from 'koa-body';
import GithubWebhookHandler from 'koa-github-webhook-handler';

const app = koa();

const githubWebhookHandler = new GithubWebhookHandler({
  path: '/webhook',
  secret: 'myhashsecret'
});

githubWebhookHandler.on('push', (event) => {
  console.log('Received a push event for %s to %s',
    event.payload.repository.name,
    event.payload.ref)
});

app.use(koaBody({formidable:{uploadDir: __dirname}}));
app.use(githubWebhookHandler.middleware());

app.listen((process.env.PORT || 3000));

API

koa-github-webhook-handler exports a class, you must instantiate it with an options object. Your options object should contain:

  • "path": the complete case sensitive path/route to match when looking at req.url for incoming requests. Any request not matching this path will yield to the "downstream" middleware.
  • "secret": this is a hash key used for creating the SHA-1 HMAC signature of the JSON blob sent by GitHub. You should register the same secret key with GitHub. Any request not delivering a X-Hub-Signature that matches the signature generated using this key against the blob will throw an HTTP 400 error code.

The middleware method return a GeneratorFunction wich act like a common middleware that you can insert into a processing chain. The next middleware is not yield if the request is successfully handled.

The class inherits form EventEmitter, so you can register handler to listen to any of the GitHub event types. Note you can be specific in your GitHub configuration about which events you wish to receive, or you can send them all.

See the GitHub Webhooks documentation for more details on the events you can receive.

Additionally, there is a special '*' event you can listen to in order to receive everything.

License

koa-github-webhook-handler is Copyright (c) 2015 TinOo512 @TinOo512 and licensed under the MIT License. All rights not explicitly granted in the MIT License are reserved. See the included LICENSE.md file for more details.