@semantic-release/commit-analyzer
Advanced tools
Comparing version 3.0.7 to 4.0.0
const {isMatchWith, isRegExp, omit} = require('lodash'); | ||
const debug = require('debug')('semantic-release:commit-analyzer'); | ||
const RELEASE_TYPES = require('./default/release-types'); | ||
@@ -27,7 +28,16 @@ const compareReleaseTypes = require('./compare-release-types'); | ||
.every(match => { | ||
if (match && compareReleaseTypes(releaseType, match.release)) { | ||
if (compareReleaseTypes(releaseType, match.release)) { | ||
releaseType = match.release; | ||
debug('The rule %o match commit with release type %o', match, releaseType); | ||
if (releaseType === RELEASE_TYPES[0]) { | ||
debug('Release type %o is the highest possible. Stop analysis.', releaseType); | ||
return false; | ||
} | ||
} else { | ||
debug( | ||
'The rule %o match commit with release type %o but the higher release type %o has already been found for this commit', | ||
match, | ||
match.release, | ||
releaseType | ||
); | ||
} | ||
@@ -34,0 +44,0 @@ return true; |
@@ -0,4 +1,6 @@ | ||
const {callbackify} = require('util'); | ||
const parser = require('conventional-commits-parser').sync; | ||
const debug = require('debug')('semantic-release:commit-analyzer'); | ||
const loadParserConfig = require('./load/parser-config'); | ||
const loadReleaseRules = require('./load/release-rules'); | ||
const parse = require('./parse'); | ||
const analyzeCommit = require('./analyze-commit'); | ||
@@ -27,35 +29,46 @@ const compareReleaseTypes = require('./compare-release-types'); | ||
*/ | ||
module.exports = async (pluginConfig = {}, {commits}, callback) => { | ||
try { | ||
const releaseRules = loadReleaseRules(pluginConfig); | ||
const config = await loadParserConfig(pluginConfig); | ||
let releaseType = null; | ||
async function commitAnalyzer(pluginConfig, {commits, logger}, callback) { | ||
const releaseRules = loadReleaseRules(pluginConfig); | ||
const config = await loadParserConfig(pluginConfig); | ||
let releaseType = null; | ||
commits.every(rawCommit => { | ||
const commit = parse(rawCommit.message, config); | ||
let commitReleaseType; | ||
commits.every(rawCommit => { | ||
const commit = parser(rawCommit.message, config); | ||
logger.log(`Analyzing commit: %s`, rawCommit.message); | ||
let commitReleaseType; | ||
// Determine release type based on custom releaseRules | ||
if (releaseRules) { | ||
commitReleaseType = analyzeCommit(releaseRules, commit); | ||
// Determine release type based on custom releaseRules | ||
if (releaseRules) { | ||
debug('Analyzing with custom rules'); | ||
commitReleaseType = analyzeCommit(releaseRules, commit); | ||
if (commitReleaseType) { | ||
logger.log('The release type for the commit is %s', commitReleaseType); | ||
} | ||
// If no custom releaseRules or none matched the commit, try with default releaseRules | ||
if (!commitReleaseType) { | ||
commitReleaseType = analyzeCommit(DEFAULT_RELEASE_RULES, commit); | ||
} | ||
// If no custom releaseRules or none matched the commit, try with default releaseRules | ||
if (!commitReleaseType) { | ||
debug('Analyzing with default rules'); | ||
commitReleaseType = analyzeCommit(DEFAULT_RELEASE_RULES, commit); | ||
if (commitReleaseType) { | ||
logger.log('The release type for the commit is %s', commitReleaseType); | ||
} else { | ||
logger.log('The commit should not trigger a release'); | ||
} | ||
// Set releaseType if commit's release type is higher | ||
if (commitReleaseType && compareReleaseTypes(releaseType, commitReleaseType)) { | ||
releaseType = commitReleaseType; | ||
} | ||
} | ||
// Set releaseType if commit's release type is higher | ||
if (commitReleaseType && compareReleaseTypes(releaseType, commitReleaseType)) { | ||
releaseType = commitReleaseType; | ||
} | ||
// Break loop if releaseType is the highest | ||
if (releaseType === RELEASE_TYPES[0]) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
callback(null, releaseType); | ||
} catch (err) { | ||
callback(err); | ||
} | ||
}; | ||
// Break loop if releaseType is the highest | ||
if (releaseType === RELEASE_TYPES[0]) { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
logger.log('Analysis of %s commits complete: %s release', commits.length, releaseType || 'no'); | ||
return releaseType; | ||
} | ||
module.exports = callbackify(commitAnalyzer); |
@@ -0,5 +1,4 @@ | ||
const {promisify} = require('util'); | ||
const importFrom = require('import-from'); | ||
const pify = require('pify'); | ||
const {mergeWith} = require('lodash'); | ||
const SemanticReleaseError = require('@semantic-release/error'); | ||
const conventionalChangelogAngular = require('conventional-changelog-angular'); | ||
@@ -20,13 +19,5 @@ | ||
const presetPackage = `conventional-changelog-${preset.toLowerCase()}`; | ||
try { | ||
loadedConfig = importFrom.silent(__dirname, presetPackage) || importFrom(process.cwd(), presetPackage); | ||
} catch (err) { | ||
throw new SemanticReleaseError(`Preset: "${preset}" does not exist: ${err.message}`, err.code); | ||
} | ||
loadedConfig = importFrom.silent(__dirname, presetPackage) || importFrom(process.cwd(), presetPackage); | ||
} else if (config) { | ||
try { | ||
loadedConfig = importFrom.silent(__dirname, config) || importFrom(process.cwd(), config); | ||
} catch (err) { | ||
throw new SemanticReleaseError(`Config: "${config}" does not exist: ${err.message}`, err.code); | ||
} | ||
loadedConfig = importFrom.silent(__dirname, config) || importFrom(process.cwd(), config); | ||
} else if (!parserOpts) { | ||
@@ -37,3 +28,3 @@ loadedConfig = conventionalChangelogAngular; | ||
if (typeof loadedConfig === 'function') { | ||
loadedConfig = await pify(loadedConfig)(); | ||
loadedConfig = await promisify(loadedConfig)(); | ||
} else { | ||
@@ -40,0 +31,0 @@ loadedConfig = await loadedConfig; |
const importFrom = require('import-from'); | ||
const SemanticReleaseError = require('@semantic-release/error'); | ||
const RELEASE_TYPES = require('../default/release-types'); | ||
@@ -24,15 +23,13 @@ | ||
if (!Array.isArray(loadedReleaseRules)) { | ||
throw new SemanticReleaseError( | ||
'Error in commit-analyzer configuration: "releaseRules" must be an array of rules', | ||
'EINVALIDCONFIG' | ||
); | ||
throw new Error('Error in commit-analyzer configuration: "releaseRules" must be an array of rules'); | ||
} | ||
loadedReleaseRules.forEach(rule => { | ||
if (RELEASE_TYPES.indexOf(rule.release) === -1) { | ||
throw new SemanticReleaseError( | ||
if (!rule || !rule.release) { | ||
throw new Error('Error in commit-analyzer configuration: rules must be an object with a "release" property'); | ||
} else if (RELEASE_TYPES.indexOf(rule.release) === -1) { | ||
throw new Error( | ||
`Error in commit-analyzer configuration: "${rule.release}" is not a valid release type. Valid values are: ${JSON.stringify( | ||
RELEASE_TYPES | ||
)}`, | ||
'EINVALIDRELEASE' | ||
)}` | ||
); | ||
@@ -39,0 +36,0 @@ } |
116
package.json
@@ -1,115 +0,1 @@ | ||
{ | ||
"name": "@semantic-release/commit-analyzer", | ||
"description": "Customizable commit-analyzer plugin for semantic-release", | ||
"version": "3.0.7", | ||
"author": "Pierre Vanduynslager", | ||
"bugs": { | ||
"url": "https://github.com/semantic-release/commit-analyzer/issues" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "cz-conventional-changelog" | ||
} | ||
}, | ||
"dependencies": { | ||
"@semantic-release/error": "^2.0.0", | ||
"conventional-changelog-angular": "^1.4.0", | ||
"conventional-commits-parser": "^2.0.0", | ||
"import-from": "^2.1.0", | ||
"lodash": "^4.17.4", | ||
"pify": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.22.0", | ||
"codecov": "^2.3.0", | ||
"commitizen": "^2.9.6", | ||
"conventional-changelog-atom": "^0.1.1", | ||
"conventional-changelog-ember": "^0.2.6", | ||
"conventional-changelog-eslint": "^0.2.0", | ||
"conventional-changelog-express": "^0.2.0", | ||
"conventional-changelog-jshint": "^0.2.0", | ||
"cz-conventional-changelog": "^2.0.0", | ||
"eslint": "^4.5.0", | ||
"eslint-config-prettier": "^2.3.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.7.0", | ||
"eslint-plugin-node": "^5.1.1", | ||
"eslint-plugin-prettier": "^2.3.0", | ||
"eslint-plugin-promise": "^3.5.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"nyc": "^11.1.0", | ||
"prettier": "^1.7.2", | ||
"rimraf": "^2.6.1", | ||
"semantic-release": "^8.0.0", | ||
"tempy": "^0.2.0" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"standard", | ||
"prettier" | ||
], | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"rules": { | ||
"prettier/prettier": 2 | ||
} | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"homepage": "https://github.com/semantic-release/commit-analyzer#readme", | ||
"keywords": [ | ||
"changelog", | ||
"commit-analyzer", | ||
"conventional-changelog", | ||
"conventional-commits", | ||
"github", | ||
"publish", | ||
"release", | ||
"semantic-release" | ||
], | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"nyc": { | ||
"include": [ | ||
"lib/**/*.js" | ||
], | ||
"reporter": [ | ||
"json", | ||
"text", | ||
"html" | ||
], | ||
"all": true | ||
}, | ||
"prettier": { | ||
"printWidth": 120, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"trailingComma": "es5" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"release": { | ||
"analyzeCommits": { | ||
"path": "./lib/index.js" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/semantic-release/commit-analyzer.git" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf coverage && rimraf .nyc_output", | ||
"cm": "git-cz", | ||
"codecov": "codecov -f coverage/coverage-final.json", | ||
"lint": "eslint lib test", | ||
"pretest": "npm run clean && npm run lint", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post", | ||
"test": "nyc ava -v" | ||
} | ||
} | ||
{"name":"@semantic-release/commit-analyzer","description":"Customizable commit-analyzer plugin for semantic-release","version":"4.0.0","author":"Pierre Vanduynslager","bugs":{"url":"https://github.com/semantic-release/commit-analyzer/issues"},"config":{"commitizen":{"path":"cz-conventional-changelog"}},"dependencies":{"conventional-changelog-angular":"^1.4.0","conventional-commits-parser":"^2.0.0","debug":"^3.1.0","import-from":"^2.1.0","lodash":"^4.17.4"},"devDependencies":{"ava":"^0.23.0","codecov":"^3.0.0","commitizen":"^2.9.6","conventional-changelog-atom":"^0.1.1","conventional-changelog-ember":"^0.2.6","conventional-changelog-eslint":"^0.2.0","conventional-changelog-express":"^0.2.0","conventional-changelog-jshint":"^0.2.0","cz-conventional-changelog":"^2.0.0","eslint":"^4.5.0","eslint-config-prettier":"^2.3.0","eslint-config-standard":"^10.2.1","eslint-plugin-import":"^2.7.0","eslint-plugin-node":"^5.1.1","eslint-plugin-prettier":"^2.3.0","eslint-plugin-promise":"^3.5.0","eslint-plugin-standard":"^3.0.1","nyc":"^11.1.0","prettier":"^1.7.2","rimraf":"^2.6.1","semantic-release":"^9.0.2","sinon":"^4.0.2"},"engines":{"node":">=4"},"eslintConfig":{"extends":["standard","prettier"],"plugins":["prettier"],"rules":{"prettier/prettier":2}},"files":["lib"],"homepage":"https://github.com/semantic-release/commit-analyzer#readme","keywords":["changelog","commit-analyzer","conventional-changelog","conventional-commits","github","publish","release","semantic-release"],"license":"MIT","main":"lib/index.js","nyc":{"include":["lib/**/*.js"],"reporter":["json","text","html"],"all":true},"prettier":{"printWidth":120,"singleQuote":true,"bracketSpacing":false,"trailingComma":"es5"},"publishConfig":{"access":"public"},"release":{"analyzeCommits":{"path":"./lib/index.js"}},"repository":{"type":"git","url":"https://github.com/semantic-release/commit-analyzer.git"},"scripts":{"clean":"rimraf coverage && rimraf .nyc_output","cm":"git-cz","codecov":"codecov -f coverage/coverage-final.json","lint":"eslint lib test","pretest":"npm run clean && npm run lint","semantic-release":"semantic-release","test":"nyc ava -v"}} |
5
23497
10
228
+ Addeddebug@^3.1.0
+ Addeddebug@3.2.7(transitive)
+ Addedms@2.1.3(transitive)
- Removed@semantic-release/error@^2.0.0
- Removedpify@^3.0.0
- Removed@semantic-release/error@2.2.0(transitive)