issue-maker

No, this will not be an issue maker. Promise.

Usage no npm install needed!

<script type="module">
  import issueMaker from 'https://cdn.skypack.dev/issue-maker';
</script>

README

issue-maker

No, this will not be an issue maker. Promise.

npm Travis styled with prettier Built with generator-ts-np npm

inbox

What

Helps you to report issues to issue trackers like github or gitlab. Currently gitlab is the only supported service. You can improve this package to add multiple services like github/trello/jira etc.

Install

npm i --save issue-maker

You don't have to install type definitions for typescript. It's built in.

How it works

At present only gitlab is supported. This package access gitlab apis(v4) behind the scenes.

The real use comes when used with express

Normal Usage

import { IssueMaker } from 'issue-maker';
// or
const { IssueMaker } = require('issue-maker');

create an issue maker

const gitlab = new IssueMaker({
  service: 'gitlab', // only this service is supported now
  endPoint: 'https://gitlab.com_or_your_custom', // note: no defaults set. you've to provide this
  privateToken: 'XXXX', // can be created from profile/settings page
  projectId: 888, // gotten from project settings page
});

report a simple issue like

gitlab.reportIssue({
  title: '(required) this will be issue title',
  description: '(optional) markdown **supported issue description**',
  /**
   * labels: coma separated string OR array of labels.
   * all labels should be pre-created in the service. else fails.
   * (optional)
   **/
  labels: 'by-issue-maker',
  assignee_ids: [454], // optional
  milestone_id: 56, // optional
})
  .then(()=>console.log('issue-reported'))
  .catch(err=>console.log('err occurred', err));

For applications running in express

cat

Issue maker leverages its full superpower when used with express.

Features

  • Easily create an issue
  • Issue-maker comments on the same issue if the issue happens again. Will not create a new issue.
  • If a closed issue is again occurred, issue-maker reopen the issue and comments on it.

How

You need a common error format for this to work. Import that error class

import {
  IssueMaker, // the original class
  ExpressRequestError, // error class. all errors will be of this format.
  ExpressRequestErrorType, // select the type of error you have to throw
} from 'issue-maker';

below is a sample route in which you throw an error in express.

app.get('/send/cats/to/me/with/500', (req, res, next) =>
  next(
    new ExpressRequestError( // use the err class
      ExpressRequestErrorType.INTERNAL_SERVER_ERROR, // choose err type
      new Error('testing 500 with cats api'), // put err details. (type:any)
    ),
  ),
);

your common err handler looks like: (here is where you call the issue-maker)

// in the end
app.use(requestErrHandler);

function requestErrHandler(err, req, res, next){
  if (err.statusCode >= 500 && err instanceof ExpressRequestError) {
    gitlabIssue.expressReportError(req, err, {
      labels: 'by-issue-maker', // label already created
      resLocals: res.locals, // for showing in issue description.
      databaseHost: '<host>', // for showing in issue description.
      databaseName: '<name>', // for showing in issue description.
    })
      .then(()=>console.log('issue reported'))
      .catch(err=>console.log('oh no, err', err))
  }
  /**
   * rest of the code..
   * handle err or
   * res.status(err.statusCode).send({msg:'oops'})
   **/ 
}

Version of ts-np-generator used: used version of ts-np generator

Licence

MIT © Vajahath Ahmed