gitlint-parser-base
Advanced tools
Comparing version 1.1.0 to 2.0.0
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 | ||
} |
{ | ||
"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": {}, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13993
9
315
1