File tree 1 file changed +74
-0
lines changed
1 file changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ const COMMIT_TYPES = {
2
+ breaking : 'major' ,
3
+ feat : 'minor' ,
4
+ fix : 'patch' ,
5
+ perf : 'patch' ,
6
+ build : 'patch' ,
7
+ chore : 'patch' ,
8
+ refactor : 'patch' ,
9
+ revert : 'patch' ,
10
+ docs : null ,
11
+ style : null ,
12
+ test : null ,
13
+ ci : null ,
14
+ } ;
15
+
16
+ const RELEASE_TYPES = {
17
+ 0 : 'MAJOR' ,
18
+ 1 : 'MINOR' ,
19
+ 2 : 'PATCH' ,
20
+ } ;
21
+
22
+ const config = {
23
+ whatBump : commits => {
24
+ let level = null ;
25
+ let breakingCount = 0 ;
26
+ let featureCount = 0 ;
27
+ let patchCount = 0 ;
28
+
29
+ commits . forEach ( commit => {
30
+ const locations = [ commit . body , commit . subject , commit . footer ] ;
31
+ const notesTitles = ( commit . notes || [ ] ) . map ( note => note . title ) ;
32
+ const allLocations = [ ...locations , ...notesTitles ] ;
33
+ const hasBreakingChangeText = allLocations . some ( text => text ?. includes ( 'BREAKING CHANGE' ) ) ;
34
+
35
+ if ( hasBreakingChangeText ) {
36
+ breakingCount ++ ;
37
+ return ;
38
+ }
39
+
40
+ switch ( COMMIT_TYPES [ commit . type ] ) {
41
+ case 'major' :
42
+ breakingCount ++ ;
43
+ break ;
44
+ case 'minor' :
45
+ featureCount ++ ;
46
+ break ;
47
+ case 'patch' :
48
+ patchCount ++ ;
49
+ break ;
50
+ }
51
+ } ) ;
52
+
53
+ if ( breakingCount > 0 ) {
54
+ level = 0 ;
55
+ } else if ( featureCount > 0 ) {
56
+ level = 1 ;
57
+ } else if ( patchCount > 0 ) {
58
+ level = 2 ;
59
+ }
60
+
61
+ const summary = `There are ${ breakingCount } breaking changes, ${ featureCount } features, and ${ patchCount } patches` ;
62
+ const releaseMsg = level === null ? 'No version bump needed.' : `Bumping ${ RELEASE_TYPES [ level ] } version.` ;
63
+ const reason = `${ summary } . ${ releaseMsg } ` ;
64
+
65
+ console . warn ( reason ) ;
66
+
67
+ return {
68
+ level,
69
+ reason,
70
+ } ;
71
+ } ,
72
+ } ;
73
+
74
+ module . exports = config ;
You can’t perform that action at this time.
0 commit comments