@@ -10,32 +10,28 @@ const COMMIT_HASH_LENGTH = 7;
1010 * @return {Object } the transformed commit.
1111 */
1212export default ( commit , context ) => {
13- if ( commit . notes ) {
14- commit . notes . forEach ( ( note ) => {
15- note . title = 'Breaking changes' ;
16- } ) ;
17- }
13+ const entry = types [ commit . type ] ;
1814
19- if (
20- types [ commit . type ] &&
21- ( types [ commit . type ] . changelog || ( commit . notes && commit . notes . length > 0 ) )
22- ) {
23- commit . groupType = `${
24- types [ commit . type ] . emoji ? `${ types [ commit . type ] . emoji } ` : ''
25- } ${ types [ commit . type ] . title } `;
26- } else {
27- return null ;
28- }
15+ const notes = commit . notes . map ( ( note ) => {
16+ return {
17+ ...note ,
18+ title : 'Breaking changes' ,
19+ } ;
20+ } ) ;
2921
30- if ( commit . scope === '*' ) {
31- commit . scope = '' ;
32- }
22+ if ( ! entry || ( ! entry . changelog && notes . length == 0 ) ) return null ;
3323
34- if ( typeof commit . hash === 'string' ) {
35- commit . shortHash = commit . hash . slice ( 0 , COMMIT_HASH_LENGTH ) ;
36- }
24+ const groupType = `${ entry . emoji ? `${ entry . emoji } ` : '' } ${ entry . title } ` ;
3725
38- const references = [ ] ;
26+ const scope = commit . scope === '*' ? '' : commit . scope ;
27+
28+ const shortHash =
29+ typeof commit . hash === 'string'
30+ ? commit . hash . substring ( 0 , COMMIT_HASH_LENGTH )
31+ : commit . shortHash ;
32+
33+ let subject = commit . subject ;
34+ const subjectReferences = [ ] ;
3935
4036 if ( typeof commit . subject === 'string' ) {
4137 let url = context . repository
@@ -45,31 +41,36 @@ export default (commit, context) => {
4541 if ( url ) {
4642 url += '/issues/' ;
4743 // Issue URLs.
48- commit . subject = commit . subject . replace ( / # ( \d + ) / g, ( _ , issue ) => {
49- references . push ( issue ) ;
44+ subject = subject . replace ( / # ( \d + ) / g, ( _ , issue ) => {
45+ subjectReferences . push ( issue ) ;
5046 return `[#${ issue } ](${ url } ${ issue } )` ;
5147 } ) ;
5248 }
5349
5450 if ( context . host ) {
5551 // User URLs.
56- commit . subject = commit . subject . replace (
52+ subject = subject . replace (
5753 / \B @ ( [ a - z 0 - 9 ] (?: - ? [ a - z 0 - 9 ] ) { 0 , 38 } ) / g,
5854 `[@$1](${ context . host } /$1)`
5955 ) ;
6056 }
6157 }
6258
59+ let references ;
6360 if ( commit . references ) {
6461 // Remove references that already appear in the subject
65- commit . references = commit . references . filter ( ( reference ) => {
66- if ( ! references . includes ( reference . issue ) ) {
67- return true ;
68- }
69-
70- return false ;
71- } ) ;
62+ references = commit . references . filter (
63+ ( reference ) => ! subjectReferences . includes ( reference . issue )
64+ ) ;
7265 }
7366
74- return commit ;
67+ return {
68+ notes,
69+ groupType,
70+ type : commit . type ,
71+ scope,
72+ shortHash,
73+ subject,
74+ references,
75+ } ;
7576} ;
0 commit comments