Uh oh!
There was an error while loading. Please reload this page.
forked from semantic-release/commit-analyzer
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
Latest commit
82 lines (71 loc) · 3.35 KB
/
Copy pathindex.js
File metadata and controls
82 lines (71 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const{isUndefined}=require('lodash');
constparser=require('conventional-commits-parser').sync;
constfilter=require('conventional-commits-filter');
constdebug=require('debug')('semantic-release:commit-analyzer');
constloadParserConfig=require('./lib/load-parser-config.js');
constloadReleaseRules=require('./lib/load-release-rules.js');
constanalyzeCommit=require('./lib/analyze-commit.js');
constcompareReleaseTypes=require('./lib/compare-release-types.js');
constRELEASE_TYPES=require('./lib/default-release-types.js');
constDEFAULT_RELEASE_RULES=require('./lib/default-release-rules.js');
/**
* Determine the type of release to create based on a list of commits.
*
* @param {Object} pluginConfig The plugin configuration.
* @param {String} pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
* @param {String} pluginConfig.config Requirable npm package with a custom conventional-changelog preset
* @param {String|Array} pluginConfig.releaseRules A `String` to load an external module or an `Array` of rules.
* @param {Object} pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
* @param {Object} context The semantic-release context.
* @param {Array<Object>} context.commits The commits to analyze.
* @param {String} context.cwd The current working directory.
*
* @returns {String|null} the type of release to create based on the list of commits or `null` if no release has to be done.
*/
asyncfunctionanalyzeCommits(pluginConfig,context){
const{commits, logger}=context;
constreleaseRules=loadReleaseRules(pluginConfig,context);
constconfig=awaitloadParserConfig(pluginConfig,context);
letreleaseType=null;
filter(
commits
.filter(({message, hash})=>{
if(!message.trim()){
debug('Skip commit %s with empty message',hash);
returnfalse;
}
returntrue;
})
.map(({message, ...commitProps})=>({rawMsg: message, message, ...commitProps, ...parser(message,config)}))
).every(({rawMsg, ...commit})=>{
logger.log(`Analyzing commit: %s`,rawMsg);
letcommitReleaseType;
// Determine release type based on custom releaseRules
if(releaseRules){
debug('Analyzing with custom rules');
commitReleaseType=analyzeCommit(releaseRules,commit);
}
// If no custom releaseRules or none matched the commit, try with default releaseRules
if(isUndefined(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;
}
// Break loop if releaseType is the highest
if(releaseType===RELEASE_TYPES[0]){
returnfalse;
}
returntrue;
});
logger.log('Analysis of %s commits complete: %s release',commits.length,releaseType||'no');
returnreleaseType;
}
module.exports={analyzeCommits};