1
- const { isUndefined} = require ( 'lodash' ) ;
2
- const parser = require ( 'conventional-commits-parser' ) . sync ;
3
- const filter = require ( 'conventional-commits-filter' ) ;
4
- const debug = require ( 'debug' ) ( 'semantic-release:commit-analyzer' ) ;
5
- const loadParserConfig = require ( './lib/load-parser-config.js' ) ;
6
- const loadReleaseRules = require ( './lib/load-release-rules.js' ) ;
7
- const analyzeCommit = require ( './lib/analyze-commit.js' ) ;
8
- const compareReleaseTypes = require ( './lib/compare-release-types.js' ) ;
9
- const RELEASE_TYPES = require ( './lib/default-release-types.js' ) ;
10
- const DEFAULT_RELEASE_RULES = require ( './lib/default-release-rules.js' ) ;
1
+ import { isUndefined } from "lodash-es" ;
2
+ import { sync as parser } from "conventional-commits-parser" ;
3
+ import filter from "conventional-commits-filter" ;
4
+ import debugFactory from "debug" ;
5
+ import loadParserConfig from "./lib/load-parser-config.js" ;
6
+ import loadReleaseRules from "./lib/load-release-rules.js" ;
7
+ import analyzeCommit from "./lib/analyze-commit.js" ;
8
+ import compareReleaseTypes from "./lib/compare-release-types.js" ;
9
+ import RELEASE_TYPES from "./lib/default-release-types.js" ;
10
+ import DEFAULT_RELEASE_RULES from "./lib/default-release-rules.js" ;
11
+
12
+ const debug = debugFactory ( "semantic-release:commit-analyzer" ) ;
11
13
12
14
/**
13
15
* Determine the type of release to create based on a list of commits.
14
16
*
15
17
* @param {Object } pluginConfig The plugin configuration.
16
18
* @param {String } pluginConfig.preset conventional-changelog preset ('angular', 'atom', 'codemirror', 'ember', 'eslint', 'express', 'jquery', 'jscs', 'jshint')
17
- * @param {String } pluginConfig.config Requirable npm package with a custom conventional-changelog preset
19
+ * @param {String } pluginConfig.config Requireable npm package with a custom conventional-changelog preset
18
20
* @param {String|Array } pluginConfig.releaseRules A `String` to load an external module or an `Array` of rules.
19
21
* @param {Object } pluginConfig.parserOpts Additional `conventional-changelog-parser` options that will overwrite ones loaded by `preset` or `config`.
20
22
* @param {Object } context The semantic-release context.
@@ -23,43 +25,43 @@ const DEFAULT_RELEASE_RULES = require('./lib/default-release-rules.js');
23
25
*
24
26
* @returns {String|null } the type of release to create based on the list of commits or `null` if no release has to be done.
25
27
*/
26
- async function analyzeCommits ( pluginConfig , context ) {
27
- const { commits, logger} = context ;
28
+ export async function analyzeCommits ( pluginConfig , context ) {
29
+ const { commits, logger } = context ;
28
30
const releaseRules = loadReleaseRules ( pluginConfig , context ) ;
29
31
const config = await loadParserConfig ( pluginConfig , context ) ;
30
32
let releaseType = null ;
31
33
32
34
filter (
33
35
commits
34
- . filter ( ( { message, hash} ) => {
36
+ . filter ( ( { message, hash } ) => {
35
37
if ( ! message . trim ( ) ) {
36
- debug ( ' Skip commit %s with empty message' , hash ) ;
38
+ debug ( " Skip commit %s with empty message" , hash ) ;
37
39
return false ;
38
40
}
39
41
40
42
return true ;
41
43
} )
42
- . map ( ( { message, ...commitProps } ) => ( { rawMsg : message , message, ...commitProps , ...parser ( message , config ) } ) )
43
- ) . every ( ( { rawMsg, ...commit } ) => {
44
+ . map ( ( { message, ...commitProps } ) => ( { rawMsg : message , message, ...commitProps , ...parser ( message , config ) } ) )
45
+ ) . every ( ( { rawMsg, ...commit } ) => {
44
46
logger . log ( `Analyzing commit: %s` , rawMsg ) ;
45
47
let commitReleaseType ;
46
48
47
49
// Determine release type based on custom releaseRules
48
50
if ( releaseRules ) {
49
- debug ( ' Analyzing with custom rules' ) ;
51
+ debug ( " Analyzing with custom rules" ) ;
50
52
commitReleaseType = analyzeCommit ( releaseRules , commit ) ;
51
53
}
52
54
53
55
// If no custom releaseRules or none matched the commit, try with default releaseRules
54
56
if ( isUndefined ( commitReleaseType ) ) {
55
- debug ( ' Analyzing with default rules' ) ;
57
+ debug ( " Analyzing with default rules" ) ;
56
58
commitReleaseType = analyzeCommit ( DEFAULT_RELEASE_RULES , commit ) ;
57
59
}
58
60
59
61
if ( commitReleaseType ) {
60
- logger . log ( ' The release type for the commit is %s' , commitReleaseType ) ;
62
+ logger . log ( " The release type for the commit is %s" , commitReleaseType ) ;
61
63
} else {
62
- logger . log ( ' The commit should not trigger a release' ) ;
64
+ logger . log ( " The commit should not trigger a release" ) ;
63
65
}
64
66
65
67
// Set releaseType if commit's release type is higher
@@ -74,9 +76,7 @@ async function analyzeCommits(pluginConfig, context) {
74
76
75
77
return true ;
76
78
} ) ;
77
- logger . log ( ' Analysis of %s commits complete: %s release' , commits . length , releaseType || 'no' ) ;
79
+ logger . log ( " Analysis of %s commits complete: %s release" , commits . length , releaseType || "no" ) ;
78
80
79
81
return releaseType ;
80
82
}
81
-
82
- module . exports = { analyzeCommits} ;
0 commit comments