1.1.0 • Published 5 years ago

conventional-commits-pattern-filter v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

conventional-commits-pattern-filter

Filter commits by pattern, not just reverted ones.

npm bundle size npm

Why

conventional-commits-filter filters reverted commits. conventional-commits-pattern-filter extends that ability to filter out arbitrary commits based on user defined patterns.

Use case - filtering out another app's commits

Let's say you have one codebase that is shared by many frontend apps. These apps have different deployments but commit changes to the same, git repo. E.g., consider this history:

<-- app1 wants to release a new version -- >

|
o feat: [app1]: Awesome new feature
|
o fix: [app1]: Fixed that annoying bug
|
o fix: [app2]: Squashed that bug
|
o docs: [app2]: Added awesome documentation
|
o chore: [app1]: Bump version for abc dependency
|

<-- app1 released v1.5.9 -- >

In order to create a new release, app1 wants to include all changes tagged with [app1] since v1.5.9 release. With conventional-commits-pattern-filter, it can do so:

const allCommits = conventionalCommitsParser(...)  // get commits parsed via conventional-commits-parser

const appCommits = filter({commits: allCommits, field: 'subject', pattern: '[app2]' })

// appCommits

o feat: [app1]: Awesome new feature
|
o fix: [app1]: Fixed that annoying bug
|
o chore: [app1]: Bump version for abc dependency

Use case - filtering out BREAKING CHANGES

Say you want to extract breaking changes only so that you can share it with stakeholders or do something else with them.

const breakingChanges = filter({ commits, field: 'body', pattern: /^((?!BREAKING CHANGE).)*/igm })

Alternatively, if negative lookahead is not your thing, you can use the include flag to include matching commits:

const breakingChanges = filter({ commits, field: 'body', pattern: /BREAKING CHANGE/igm, include: true })

Install

npm i conventional-commits-filter

Usage

const filter = require('conventional-commits-pattern-filter')

// given a commits array like
const commits = [
  {
    subject: 'feat: [excludeMe]: some feature',
    // other props
  },
  {
    subject: 'feat: thw best thing since sliced bread',
    // other props
  },
]

const filteredCommits = filter({ commits, field: 'subject', pattern: '[excludeMe]' })

// filteredCommits
[
    {
        subject: 'feat: thw best thing since sliced bread',
        // other props
    }
]

API

conventionalCommitsPatternFilter(options)

Returns a filtered array of commits based on the given field and pattern.

options

Type: object

commits

Type: array

Array of parsed commits returned by conventional-commits-parser

The commit object has the following structure:

{ type: 'feat',
  scope: 'scope',
  subject: 'what an amazing feature',
  merge: null,
  header: 'feat(scope): what an amazing feature',
  body: null,
  footer: 'Closes #1',
  notes: [],
  references:
   [ { action: 'Closes',
       owner: null,
       repository: null,
       issue: '1',
       raw: '#1',
       prefix: '#' } ],
  mentions: [],
  revert: null }

field

Type: string or array

Field(s) to filter on. Can be the name of any valid property/key on the commit object from commits array.

filter({ commits, field: ['subject', 'body'], pattern: '[excludeMe]' })

Note: Currently only supports simple properties. Send me a PR if you need any deep filtering!

pattern

Type: string or regex

The pattern to filter commits. Any matching commit will be excluded.

include

Type: boolean

If true, includes matching commits instead of excluding them.

License

NPM Released 2019 by Hrusikesh Panda