@jackdbd/hapi-github-issue-plugin
v1.0.0
Published
Hapi plugin that automatically creates a GitHub issue every time your app encounters an error
Downloads
2
Readme
@jackdbd/hapi-github-issue-plugin
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.
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:
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. |