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

@calmdownval/bob

v1.0.2

Published

Simple GitHub webhook event source listener

Downloads

6

Readme

Bob

A simple local(host) builder who likes to listen to GitHub webhooks.

Usage Guide

1. Install Bob

You will also need to install the Signal peer dependency.

# using NPM
npm install @calmdownval/bob @calmdownval/signal

# using Yarn
yarn add @calmdownval/bob @calmdownval/signal

2. Register GitHub Webhooks

This package is intended to be used on localhost without the need for any public endpoints. This is possible using proxy services like smee.io. Once you have a channel ready use that as your webhook URL.

Make sure to set a proper secret when registering webhooks. It is an optional feature, but when using a proxy it is the only reliable way to ensure that events you receive are in fact from GitHub.

3. Create a Listener

Create a new instance of the Listener class with configuration to suit your needs.

You can use the tls key to pass through any options accepted by NodeJS' TLS Socket, typically certificates or rejectUnauthorized for development environments.

import { Listener } from '@calmdownval/bob';

const listener = new Listener({
  secret: '<your-secret>',
  sourceURL: '<webhook-proxy-url>',
  tls: {
    rejectUnauthorized: false
  }
});

4. Bind Event Handlers

Assign event handlers using the Signal library to signals provided by the Listener instance. The handlers receive unmodified event payloads as they are received from GitHub. You can find their definitions here.

import * as Signal from '@calmdownval/signal';

Signal.on(listener.event<any>('push'), ({ data: e }) => {
  console.log(`${e.sender.login} pushed ${e.commits.length} commits into ${e.repository.full_name}.`);
});

The event method of the Listener class returns a signal triggered when the GitHub webhook specified by the first argument is invoked. If you omit this argument or use the Listener.ANY_EVENT constant you will receive a signal that triggers on any GitHub webhook received. This is useful if you wish to switch between event types manually.

Using the type argument of the event method you can inject typings of the event. GitHub webhook typings are out of scope of this library, instead consider using @octokit/webhooks-definitions.