@@ -12,59 +12,51 @@ const COMMIT_HASH_LENGTH = 7;
1212 * @return {Object } the transformed commit.
1313 */
1414module . exports = ( commit , context ) => {
15- if ( commit . notes ) {
16- commit . notes . forEach ( note => {
17- note . title = 'Breaking changes' ;
18- } ) ;
19- }
20-
21- if ( types . types [ commit . type ] && ( types . types [ commit . type ] . changelog || ( commit . notes && commit . notes . length > 0 ) ) ) {
22- commit . groupType = `${ types . types [ commit . type ] . emoji ? `${ types . types [ commit . type ] . emoji } ` : '' } ${
23- types . types [ commit . type ] . title
24- } `;
25- commit . type = commit . groupType ;
26- } else {
15+ const commitType = types . types [ commit . type ] ;
16+ const notes = Array . isArray ( commit . notes )
17+ ? commit . notes . map ( note => ( {
18+ ...note ,
19+ title : 'Breaking changes' ,
20+ } ) )
21+ : [ ] ;
22+
23+ if ( ! commitType || ( ! commitType . changelog && notes . length === 0 ) ) {
2724 return null ;
2825 }
2926
30- if ( commit . scope === '*' ) {
31- commit . scope = '' ;
32- }
33-
34- if ( typeof commit . hash === 'string' ) {
35- commit . shortHash = commit . hash . slice ( 0 , COMMIT_HASH_LENGTH ) ;
36- }
27+ const groupType = `${ commitType . emoji ? `${ commitType . emoji } ` : '' } ${ commitType . title } ` ;
3728
3829 const references = [ ] ;
30+ let subject = commit . subject ;
3931
40- if ( typeof commit . subject === 'string' ) {
32+ if ( typeof subject === 'string' ) {
4133 let url = context . repository ? `${ context . host } /${ context . owner } /${ context . repository } ` : context . repoUrl ;
4234
4335 if ( url ) {
4436 url += '/issues/' ;
4537 // Issue URLs.
46- commit . subject = commit . subject . replace ( / # ( \d + ) / g, ( _ , issue ) => {
38+ subject = subject . replace ( / # ( \d + ) / g, ( _ , issue ) => {
4739 references . push ( issue ) ;
4840 return `[#${ issue } ](${ url } ${ issue } )` ;
4941 } ) ;
5042 }
5143
5244 if ( context . host ) {
5345 // User URLs.
54- commit . subject = commit . subject . replace ( / \B @ ( [ a - z 0 - 9 ] (?: - ? [ a - z 0 - 9 ] ) { 0 , 38 } ) / g, `[@$1](${ context . host } /$1)` ) ;
46+ subject = subject . replace ( / \B @ ( [ a - z 0 - 9 ] (?: - ? [ a - z 0 - 9 ] ) { 0 , 38 } ) / g, `[@$1](${ context . host } /$1)` ) ;
5547 }
5648 }
5749
58- if ( commit . references ) {
59- // Remove references that already appear in the subject
60- commit . references = commit . references . filter ( reference => {
61- if ( ! references . includes ( reference . issue ) ) {
62- return true ;
63- }
64-
65- return false ;
66- } ) ;
67- }
68-
69- return commit ;
50+ return {
51+ ... commit ,
52+ groupType ,
53+ type : groupType ,
54+ scope : commit . scope === '*' ? '' : commit . scope ,
55+ shortHash : typeof commit . hash === 'string' ? commit . hash . slice ( 0 , COMMIT_HASH_LENGTH ) : commit . shortHash ,
56+ subject ,
57+ notes ,
58+ references : Array . isArray ( commit . references )
59+ ? commit . references . filter ( reference => ! references . includes ( reference . issue ) )
60+ : commit . references ,
61+ } ;
7062} ;
0 commit comments