Giter Club home page Giter Club logo

issue-parser's Introduction

issue-parser

Parser for Github, GitLab and Bitbucket issues actions, references and mentions

Node CI Workflow Status

The parser can identify:

Install

$ npm install --save issue-parser

Usage

GitHub format

const issueParser = require('issue-parser');
const parse = issueParser('github');

parse('Issue description, ref user/package#1, Fix #2, Duplicate of #3 /cc @user');
/*
{
  refs: [{raw: 'user/package#1', slug: 'user/package', prefix: '#', issue: '1'}],
  actions: {
    close: [{raw: 'Fix #2', action: 'Fix', prefix: '#', issue: '2'}],
    duplicate: [{raw: 'Duplicate of #3', action: 'Duplicate of', prefix: '#', issue: '3'}],
  },
  mentions: [{raw: '@user', prefix: '@', user: 'user'}],
}
*/

GitLab format

const issueParser = require('issue-parser');
const parse = issueParser('gitlab');

parse('Issue description, ref group/user/package#1, !2, implement #3, /duplicate #4 /cc @user');
/*
{
  refs: [
    {raw: 'group/user/package#1', slug: 'group/user/package', prefix: '#', issue: '1'},
    {raw: '!2', slug: 'group/user/package', prefix: '!', issue: '2'},
  ],
  actions: {
    close: [{raw: 'implement #3', action: 'Implement', prefix: '#', issue: '4'}],
    duplicate: [{raw: 'Duplicate of #4', action: 'Duplicate of', prefix: '#', issue: '4'}],
  },
  mentions: [{raw: '@user', prefix: '@', user: 'user'}],
}
*/

Bitbucket format

const issueParser = require('issue-parser');
const parse = issueParser('bitbucket');

parse('Issue description, ref user/package#1, fixing #2. /cc @user');
/*
{
  refs: [{raw: 'user/package#1', slug: 'user/package', prefix: '#', issue: '1'}],
  actions: {
    close: [{raw: 'fixing #2', action: 'Fixing', prefix: '#', issue: '2'}],
  },
  mentions: [{raw: '@user', prefix: '@', user: 'user'}],
}
*/

Custom format

const issueParser = require('issue-parser');
const parse = issueParser({actions: {fix: ['complete'], hold: ['holds up']}, issuePrefixes: ['πŸ›']});

parse('Issue description, related to user/packageπŸ›1, Complete πŸ›2, holds up πŸ›3');
/*
{
  refs: [{raw: 'user/packageπŸ›1', slug: 'user/package', prefix: 'πŸ›', issue: '1'}],
  actions: {
    fix: [{raw: 'Complete πŸ›2', action: 'Complete', prefix: 'πŸ›', issue: '2'}],
    hold: [{raw: 'holds up πŸ›3', action: 'Holds up', prefix: 'πŸ›', issue: '3'}],
  },
}
*/

Extend existing format

const issueParser = require('issue-parser');
const parse = issueParser('github', {actions: {parent: ['parent of'], related: ['related to']}});

parse('Issue description, ref user/package#1, Fix #2, Parent of #3, related to #4 /cc @user');
/*
{
  refs: [{raw: 'user/package#1', slug: 'user/package', prefix: '#', issue: '1'}],
  actions: {
    close: [{raw: 'Fix #2', action: 'Fix', prefix: '#', issue: '2'}],
    parent: [{raw: 'Parent of #3', action: 'Parent of', prefix: '#', issue: '3'}],
    related: [{raw: 'related to #4', action: 'Related to', prefix: '#', issue: '4'}],
  },
  mentions: [{raw: '@user', prefix: '@', user: 'user'}],
}
*/

Features

Parse references

#1
{refs: [{raw: '#1', slug: undefined, prefix: '#', issue: '1'}]}

Parse repository slug

owner/repo#1
{refs: [{raw: 'owner/repo#1', slug: 'owner/repo', prefix: '#', issue: '1'}]}

Parse closing keywords

Fix #1
{actions: {close: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]}}

Parse duplicate keywords

Duplicate of #1
{actions: {duplicate: [{raw: 'Duplicate of #1', action: 'Duplicate of', slug: undefined, prefix: '#', issue: '1'}]}}

Parse user mentions

@user
{mentions: [{raw: '@user', prefix: '@', user: 'user'}]}

Parse references with full issue URL

https://github.com/owner/repo/pull/1

Fix https://github.com/owner/repo/issues/2
{
  refs: [{raw: 'https://github.com/owner/repo/pull/1', slug: 'owner/repo', prefix: undefined, issue: '1'},]
  actions: {
    close: [
      {raw: 'Fix https://github.com/owner/repo/issues/2', action: 'Fix', slug: 'owner/repo', prefix: undefined, issue: '2'}
    ]
  }
}

Ignore keywords case

FIX #1
{actions: {close: [{raw: 'FIX #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]}}

Support delimiters between action keyword and issue

Fix: #1
{actions: {close: [{raw: 'Fix: #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]}}

Ignore references in back-tick quotes

Fix #1 `Fix #2` @user1 `@user2`
{
  actions: {close: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]},
  mentions: [{raw: '@user1', prefix: '@', user: 'user1'}]
}

Include references in escaped back-tick quotes

\`Fix #1\` \`@user\`
{
  actions: {close: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]},
  mentions: [{raw: '@user1', prefix: '@', user: 'user1'}]
}

Ignore references in fenced blocks

Fix #1

```js
console.log('Fix #2');
```

@user1

```js
console.log('@user2');
```
{
  actions: {close: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]},
  mentions: [{raw: '@user1', prefix: '@', user: 'user1'}]
}

Include references in escaped fenced blocks

\`\`\`
Fix #1
\`\`\`

\`\`\`
@user
\`\`\`
{
  actions: {close: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]},
  mentions: [{raw: '@user', prefix: '@', user: 'user'}]
}

Ignore references in <code> tags

Fix #1
<code>Fix #2</code>
<code><code>Fix #3</code></code>
@user1
<code>@user2</code>
{
  actions: {close: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]},
  mentions: [{raw: '@user1', prefix: '@', user: 'user1'}]
}

Include references in escaped <code> tags

`<code>`Fix #1`</code>`
`<code>`@user`</code>`
{
  actions: {close: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]},
  mentions: [{raw: '@user', prefix: '@', user: 'user'}]
}

Ignore malformed references

Fix #1 Fix #2a Fix a#3
{actions: {close: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]}}

API

issueParser([options], [overrides]) => parse

Create a parser.

options

Type: Object String
Parser options. Can be github, gitlab or bitbucket for predefined options, or an object for custom options.

actions

Type: Object
Default: {close: ['close', 'closes', 'closed', 'closing', 'fix', 'fixes', 'fixed', 'fixing', 'resolve', 'resolves', 'resolved', 'resolving', 'implement', 'implements', 'implemented', 'implementing'], duplicate: ['Duplicate of', '/duplicate']}

Object with type of action as key and array of keywords as value.

Each keyword match will be placed in the corresponding property of the result action object. For example the with the configuration {actions: fix: ['fixed', 'fixing']} each action matching fixed or fixing will be under result.actions.fix.

delimiters

Type: Array<String> String
Default: [':']

List of delimiter characters allowed between an action keywords and the issue reference. The characters space ( ) and tab ( ) are always allowed.

mentionsPrefixes

Type: Array<String> String
Default: ['@']

List of keywords used to identify user mentions.

issuePrefixes

Type: Array<String> String
Default: ['#', 'gh-']

List of keywords used to identify issues and pull requests.

hosts

Type: Array<String> String
Default: ['https://github.com', 'https://gitlab.com']

List of base URL used to identify issues and pull requests with full URL.

issueURLSegments

Type: Array<String> String
Default: ['issues', 'pull', 'merge_requests']

List of URL segment used to identify issues and pull requests with full URL.

overrides

Type: Object
Option overrides. Useful when using predefined options (such as github, gitlab or bitbucket). The overrides object can define the same properties as options.

For example, the following will use all the github predefined options but with a different hosts option:

const issueParser = require('issue-parser');
const parse = issueParser('github', {hosts: ['https://custom-url.com']});

parse(text) => Result

Parse an issue description and returns a Result object.

text

Type: String

Issue text to parse.

Result

actions

Type: Object

List of matching actions by type.
Each type of action is an array of objects with the following properties:

Name Type Description
raw String The raw value parsed, for example Fix #1.
action String The keyword used to identify the action, capitalized.
slug String The repository owner and name, for issue referred as <owner>/<repo>#<issue number>.
prefix String The prefix used to identify the issue.
issue String The issue number.

refs

Type: Array<Object>

List of issues and pull requests referenced, but not matched with an action.
Each reference has the following properties:

Name Type Description
raw String The raw value parsed, for example #1.
slug String The repository owner and name, for issue referred as <owner>/<repo>#<issue number>.
prefix String The prefix used to identify the issue.
issue String The issue number.

mentions

Type: Array<Object>

List of users mentioned.
Each mention has the following properties:

Name Type Description
raw String The raw value parsed, for example @user.
prefix String The prefix used to identify the mention.
user String The user name

allRefs

Type: Array<Object>

List of all issues and pull requests referenced or matching an action.
Each reference has the following properties:

Name Type Description
raw String The raw value parsed, for example Fix #1.
action String The keyword used to identify the action or the duplicate, capitalized. Only if matched by an action.
slug String The repository owner and name, for issue referred as <owner>/<repo>#<issue number>.
prefix String The prefix used to identify the issue.
issue String The issue number.

issue-parser's People

Contributors

gr2m avatar greenkeeper[bot] avatar pvdlg avatar renovate[bot] avatar rsarky avatar travi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

issue-parser's Issues

An in-range update of semantic-release is breaking the build 🚨

Version 15.9.7 of semantic-release was just published.

Branch Build failing 🚨
Dependency semantic-release
Current Version 15.9.6
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes v15.9.7

15.9.7 (2018-08-10)

Reverts

  • "fix: do not convert ssh repositoryUrl to https" (93377eb)
Commits

The new version differs by 1 commits.

  • 93377eb revert: "fix: do not convert ssh repositoryUrl to https"

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of codecov is breaking the build 🚨

Version 3.0.3 of codecov was just published.

Branch Build failing 🚨
Dependency codecov
Current Version 3.0.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

codecov is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v3.0.3

Fix for not git repos

Commits

The new version differs by 3 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm codecov Unavailable

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/setup-node v4.0.3@1e60f620b9541d16bece96c5465dc8ee9832be0b
.github/workflows/test.yml
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/setup-node v4.0.3@1e60f620b9541d16bece96c5465dc8ee9832be0b
  • actions/checkout v4.1.7@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/setup-node v4.0.3@1e60f620b9541d16bece96c5465dc8ee9832be0b
npm
package.json
  • lodash.capitalize ^4.2.1
  • lodash.escaperegexp ^4.1.2
  • lodash.isplainobject ^4.0.6
  • lodash.isstring ^4.0.1
  • lodash.uniqby ^4.7.0
  • ava 6.1.3
  • codecov 3.8.3
  • lockfile-lint 4.14.0
  • ls-engines 0.9.3
  • npm-run-all2 6.2.2
  • nyc 17.0.0
  • publint 0.2.10
  • xo 0.28.3
  • node ^18.17 || >=20.6.1
nvm
.nvmrc
  • node 20

  • Check this box to trigger a request for Renovate to run again on this repository

Handle Gitlab closing comma separated actions

Parser configuration

const issueParser = require('issue-parser');
const parse = issueParser('gitlab');

Text to parse

From: Managing Issues > Default closing pattern

Awesome commit message

Fix #20, Fixes #21 and Closes group/otherproject#22.
This commit is also related to #17 and fixes #18, #19
and https://gitlab.com/group/otherproject/issues/23.

Current Behavior

{
  "actions": {
    "close": [
      {
        "raw": "Fix #20",
        "action": "Fix",
        "prefix": "#",
        "issue": "20"
      },
      {
        "raw": "Fixes #21",
        "action": "Fixes",
        "prefix": "#",
        "issue": "21"
      },
      {
        "raw": "Closes group/otherproject#22",
        "action": "Closes",
        "slug": "group/otherproject",
        "prefix": "#",
        "issue": "22"
      },
      {
        "raw": "fixes #18",
        "action": "Fixes",
        "prefix": "#",
        "issue": "18"
      }
    ],
    "duplicate": []
  },
  "refs": [
    {
      "raw": "#17",
      "prefix": "#",
      "issue": "17"
    },
    {
      "raw": "#19",
      "prefix": "#",
      "issue": "19"
    },
    {
      "raw": "https://gitlab.com/group/otherproject/issues/23",
      "slug": "group/otherproject",
      "issue": "23"
    }
  ],
  "mentions": []
}

Expected behavior

Issue 19 and 23 should be interpreted as close.

If it helps, their parser code is at: closing_issue_extractor.rb

{
  "actions": {
    "close": [
      {
        "raw": "Fix #20",
        "action": "Fix",
        "prefix": "#",
        "issue": "20"
      },
      {
        "raw": "Fixes #21",
        "action": "Fixes",
        "prefix": "#",
        "issue": "21"
      },
      {
        "raw": "Closes group/otherproject#22",
        "action": "Closes",
        "slug": "group/otherproject",
        "prefix": "#",
        "issue": "22"
      },
      {
        "raw": "fixes #18",
        "action": "Fixes",
        "prefix": "#",
        "issue": "18"
      },
      {
        "raw": "#19",
        "prefix": "#",
        "issue": "19"
      },
      {
        "raw": "https://gitlab.com/group/otherproject/issues/23",
        "slug": "group/otherproject",
        "issue": "23"
      }
    ],
    "duplicate": []
  },
  "refs": [
    {
      "raw": "#17",
      "prefix": "#",
      "issue": "17"
    },
    {
      "raw": "#19",
      "prefix": "#",
      "issue": "19"
    },
    {
      "raw": "https://gitlab.com/group/otherproject/issues/23",
      "slug": "group/otherproject",
      "issue": "23"
    }
  ],
  "mentions": []
}

An in-range update of semantic-release is breaking the build 🚨

Version 15.9.1 of semantic-release was just published.

Branch Build failing 🚨
Dependency semantic-release
Current Version 15.9.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes v15.9.1

15.9.1 (2018-07-30)

Bug Fixes

  • clarify EPLUGINCONF error message (d8c84a0)
Commits

The new version differs by 3 commits.

  • b2d82c2 docs: specify for each step if one or more plugins are required/allowed
  • 31ec1eb docs: fix configuration doc syntax
  • d8c84a0 fix: clarify EPLUGINCONF error message

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of semantic-release is breaking the build 🚨

Version 15.9.2 of semantic-release was just published.

Branch Build failing 🚨
Dependency semantic-release
Current Version 15.9.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes v15.9.2

15.9.2 (2018-07-30)

Bug Fixes

  • also hide sensitive info when loggin from cli.js (43d0646)
Commits

The new version differs by 1 commits.

  • 43d0646 fix: also hide sensitive info when loggin from cli.js

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Handle multiple comma separated actions.

Parser configuration

parse('github')

Text to parse

Fixes #1,#2

Current Behavior

{ actions:
   [ { raw: 'Fixes #1',
       action: 'Fixes',
       slug: undefined,
       prefix: '#',
       issue: '1' } ],
  refs: [ { raw: '#2', slug: undefined, prefix: '#', issue: '2' } ],
  duplicates: [],
  mentions: [] }

Expected behavior

Should return 2 actions instead of 1 action and 1 ref.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.