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

arbitrary-gh-webhook

v0.1.1

Published

QuickCheck data for GitHub webhooks.

Downloads

11

Readme

Arbitrary GitHub Webhooks

arbitrary-gh-webhook on npm CI Results Code Coverage License details

QuickCheck data for GitHub Webhooks.

Status

arbitrary-gh-webhook is partially developed, with each webhook being implemented in two stages.

Stage 1 webhooks are roughly implemented, but may use generic "random strings" in some places instead of properly-formatted URLs, and might have some values that don't match (labels may belong to a different repository than the issue they are attached to).

Stage 2 will attempt to fix some of these issues by doing more post-processing of the generated data to make sure data makes sense.

Status of Each Webhook

  • ArbitraryIssuesEvent
    Stage 1 added in v0.1.0

Example Usage

Raw Webhook Testing

Want semi-random IssuesEvent webhooks to test an issueHasLabels function?

Let's setup a testing environment. You'll need JSVerify, a standard JavaScript QuickCheck library.

We'll also be using ava-verify in these examples to easily use JSVerify with the AVA test runner.

const jsc = require("jsverify");
jsc.ava = require("ava-verify");

Then grab ArbitraryIssuesEvent from this project, as well as the code you want to test (issueHasLabels):

const ArbitraryIssuesEvent = require("arbitrary-gh-webhook/hooks/ArbitraryIssuesEvent");
const issueHasLabels = require("../issueHasLabels");

Now write your tests! Thanks to JSVerify and ava-verify, they will run multiple times (by default, 100 iterations) with different test data.

jsc.ava({
    suite: "issueHasLabels returns a boolean",
  }, [
    ArbitraryIssuesEvent.build(),
  ], (t, issueData) => {
    t.is(typeof issueHasLabels(issueData), "boolean");
  }
);

Additionally, arbitrary-gh-webhook was built using ConfigurableArbitrary, which allows you to tweak how webhooks are built.

For instance, you might want to test specifically what happens if the webhook returns an issue with a specific number of labels.

You can override specific parts of the webhook, while the rest is still randomly created:

const jsc = require("jsverify");
jsc.ava = require("ava-verify");
const arrayRange = require("jsverify-array-range");

const ArbitraryIssuesEvent = require("arbitrary-gh-webhook/hooks/ArbitraryIssuesEvent");
const WebhookIssue = require("arbitrary-gh-webhook/data/WebhookIssue");
const WebhookLabelList = require("arbitrary-gh-webhook/data/WebhookLabelList");

const issueHasLabels = require("../issueHasLabels");


jsc.ava({
    suite: "issueHasLabels returns 'false' if Issue has 0 labels",
  }, [
    ArbitraryIssuesEvent.build({
      issue: WebhookIssue.build({
        labels: WebhookLabelList.build({ max: 0 }),
      }),
    }),
  ], (t, issueData) => {
    t.is(issueHasLabels(issueData), false);
  }
);

jsc.ava({
    suite: "issueHasLabels returns 'true' if Issue has 1+ labels",
  }, [
    ArbitraryIssuesEvent.build({
      issue: WebhookIssue.build({
        labels: WebhookLabelList.build({ min: 1 }),
      }),
    }),
  ], (t, issueData) => {
    t.is(issueHasLabels(issueData), true);
  }
);

Usage with SuperAgent

Requests include a built-in SuperAgent module, so you can easily send requests to a webserver.

Let's say you've got a standard Express server that should handle the IssuesEvent.

const jsc = require("jsverify");
jsc.ava = require("ava-verify");
const ArbitraryIssuesEvent = require("arbitrary-gh-webhook/hooks/ArbitraryIssuesEvent");
const request = require("supertest");

const Server = require("../index.js");

jsc.ava({
    suite: "server stores new issues",
  }, [
    ArbitraryIssuesEvent.build(),
  ], async (t, webhook) => {
    t.plan(2);
    const server = new Server();
    await request(server.app)
      .post("/hook/gh/issues")
      .use(webhook.superagent)
      .then(res => t.is(res.status, 200));
    t.true(server.hasIssue(webhook.body.issue.id));
  }
);