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

github-notifier

v2.2.0

Published

Listen for GitHub updates using an EventEmitter.

Downloads

2

Readme

node-github-notifier

An EventEmitter built on top of GitHub Webhooks.

Support this project by donating on Gratipay.

Installation

npm install github-notifier

Usage

var http = require( "http" );
var Notifier = require( "github-notifier" ).Notifier;
var notifier = new Notifier();
var server = http.createServer();
server.on( "request", notifier.handler );
server.listen( 8000 );

notifier.on( "scottgonzalez/node-github-notifier/push/heads/**", function( data ) {
	console.log( "New commit: " + data.commit );
});

API

All events follow a simple format: {username}/{repo}/{eventname}

The notifier is an EventEmitter2 instance and therefore supports namespacing, which makes the notifier quite powerful and flexible. Notifiers have a handler method which is designed to be used as an HTTP request listener. In the basic usage above, the notifier will listen to all requests, however this can be controlled however you want since it is just a request listener. This also makes it very simple to integrate into an existing server.

The notifier supports both application/x-www-form-urlencoded and application/json payload formats and will detect the content type automatically.

Events

All events receive a single data parameter with some common data and event-specific data.

Some events will also have additional levels of data in the event name in order to provide simpler customizations via wildcards. This is currently limited to push events, but may be extended by adding additional processors to the notifier.

Common Event Data

  • type: The type of event. See Webhook Events for a full list of possible events.
  • owner: The owner of the repo.
  • repo: The name of the repo.
  • payload: The raw GitHub payload data. See Event Types & Payloads for detailed information on the payloads for each event type.

pull_request

Additional data:

  • pr: The pull request number. This is the same as payload.number.
  • base: The SHA of the base. This is the same as payload.pull_request.base.sha.
  • head: The SHA of the head. This is the same as payload.pull_request.head.sha.
  • range: The commit range for the pull request.

push

Push events add the refspec to the event name. For example, a push to the master branch of scottgonzalez/node-github-notifier will result in a scottgonzalez/node-github-notifier/push/heads/master event and a push that creates a 1.2.3 tag will result in a scottgonzalez/node-github-notifier/push/tags/1.2.3 event.

Additional data:

  • commit: The HEAD of the branch after the push. This is the same as payload.after.
  • branch: The name of the branch, if a branch was pushed.
  • tag: The name of the tag, if a tag was pushed.

Processors

In order to provide event-specific customizations of data and event names, additional processors can be added to Notifier.prototype.processors (or on the processors property of a notifier instance). processors is just a hash of methods where the key is the event name and the value is a function with the following signature:

function( payload )

  • payload (Object): The payload, containing the headers and data from the webhook.
    • headers (Object): A hash of the headers sent by GitHub.
    • data (Object): The actual payload sent by GitHub.
  • return value: Object
    • data (Object): Additional data to include with the event.
    • postfix (String; optional): Additional levels of data to append to the event name.

License

Copyright Scott González. Released under the terms of the MIT license.


Support this project by donating on Gratipay.