Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gitlint-parser-base

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitlint-parser-base - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

test/fixtures/commit.json

61

index.js

@@ -7,4 +7,4 @@ 'use strict'

constructor(str, validator) {
if (typeof str !== 'string') {
throw new TypeError('str must be a string')
if (typeof str !== 'string' && typeof str !== 'object') {
throw new TypeError('str must be a string or an object')
}

@@ -17,3 +17,15 @@ if (!validator || typeof validator !== 'object') {

}
this._raw = str
if (typeof str === 'string') {
this._type = 'cli'
this._rawstr = str
this._raw = str
} else {
this._type = 'github-api'
if (!str || !str.sha) {
throw new Error('Invalid api format')
}
this._raw = transformAPIJson(str)
this._rawstr = this._raw.message
}
this.sha = null

@@ -49,2 +61,23 @@ this.title = null

parse() {
switch (this._type) {
case 'cli':
this._parseCLI()
break
case 'github-api':
this._parseAPI()
break
}
}
_parseAPI() {
this.sha = this._raw.sha
this.date = this._raw.date
this.author = this._raw.author
const splits = this._rawstr.split('\n')
this.title = splits.shift()
this.body = splits
}
_parseCLI() {
const splits = this._raw.split('\n')

@@ -89,1 +122,23 @@ const commitLine = splits.shift()

}
function transformAPIJson(obj) {
const commit = obj.commit && typeof obj.commit === 'object'
&& (obj.commit.author || obj.commit.committer)
? obj.commit
: obj
const out = {
sha: obj.sha
, author: null
, date: null
, message: commit.message
}
const author = commit.author || commit.committer
if (author) {
out.author = `${author.name} <${author.email}>`
out.date = author.date
}
return out
}

4

package.json
{
"name": "gitlint-parser-base",
"version": "1.1.0",
"version": "2.0.0",
"description": "base parser for gitlint",

@@ -8,3 +8,3 @@ "main": "index.js",

"pretest": "lintit",
"test": "tap test.js --cov"
"test": "tap test --cov"
},

@@ -11,0 +11,0 @@ "dependencies": {},

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc