@jackdbd/hapi-github-issue-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@jackdbd/hapi-github-issue-plugin

npm version Snyk Vulnerabilities for npm package

Hapi plugin that automatically creates a GitHub issue when a request matches one of the rules you defined.

Installation

npm install @jackdbd/hapi-github-issue-plugin

Preliminary Operations

GitHub personal access token

This Hapi plugin makes a POST request to {{GitHub-API}}/repos/:owner/:repo/issues whenever an HTTP request matches one of the predicates used to configure the plugin itself. To allow this plugin to create an issue in your GitHub repository, you need to configure it with a GitHub personal access token with the required OAuth scopes. You can reuse an existing personal access token, or create a new one.

OAuth scopes for the hapi-github-issue-plugin

Usage

If you register this plugin without passing any options...

import githubIssue from '@jackdbd/hapi-github-issue-plugin'

export const app = async (config) => {

  const server = Hapi.server({ port: 8080 })

  await server.register({ plugin: githubIssue })

  return { server }
}

...it will catch any internal server error and create a GitHub issue like this one:

Telegram message about an internal server error in your Hapi app

You can create a GitHub issue for any kind of request handled by yout Hapi application, as long as you define a request matcher for it. For example, here I configure the plugin to create an issue every time the Hapi app responds with HTTP 500 internal server error, or when it responds with HTTP 418 I'm a Teapot.

// import the plugin itself
import githubIssue from '@jackdbd/hapi-github-issue-plugin'

// define the functions that create the issue title/body somewhere
// in your app, or import them from a library.
import {
  defaultTitleFunction,
  defaultBodyFunction
} from '@jackdbd/hapi-github-issue-plugin/texts'

// define your request predicates somewhere in your app,
// or import them from a library.
import {
  isServerRequestError,
  isUnauthorizedRequestError
} from '@jackdbd/hapi-request-event-predicates'

export const app = async (config) => {

  const server = Hapi.server({ port: 8080 })

  await server.register({
    plugin: githubIssue,
    options: {
      request_event_matchers: [
        // create an issues every time the Hapi app responds with
        // HTTP 500 Internal Server Error, and assign it to bob.
        {
          predicate: isServerRequestError,
          title: defaultTitleFunction,
          body: defaultBodyFunction,
          assignees: ['bob'],
          labels: ['bug', 'matsuri-test']
        },
        // create an issues every time the Hapi app responds with
        // HTTP 418 I'm a teapot, and assign it to john.
        {
          predicate: isTeapotRequestError,
          title: defaultTitleFunction,
          body: defaultBodyFunction,
          assignees: ['john'],
          labels: ['teapot', 'matsuri-test']
        }
      ]
    }
  })

  return { server }
}

Configuration

Options

Option Default Explanation
request_event_matchers see defaultRequestEventMatchers() in register.ts Each rule controls which request matches, and which title, body, assignees, milestone, labels to use when creating the GitHub issue.

Package Sidebar

Install

npm i @jackdbd/hapi-github-issue-plugin

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

43.9 kB

Total Files

55

Last publish

Collaborators

  • jackdbd