99// npm modules
1010import chalk from 'chalk' ;
1111import denodeify from 'denodeify' ;
12+ import gitRawCommits from 'git-raw-commits' ;
1213import meow from 'meow' ;
1314import merge from 'lodash.merge' ;
1415import pick from 'lodash.pick' ;
@@ -52,10 +53,11 @@ const cli = meow({
5253 } ,
5354 // flag defaults
5455 default : {
56+ color : true ,
57+ edit : false ,
5558 from : null ,
56- to : null ,
57- e : true ,
5859 preset : 'angular' ,
60+ to : null ,
5961 quiet : false
6062 } ,
6163 // fail on unknown
@@ -64,6 +66,20 @@ const cli = meow({
6466 }
6567} ) ;
6668
69+ // Get commit messages
70+ // TODO: move this to an own moduleddd
71+ function getCommits ( options ) {
72+ return new Promise ( ( resolve , reject ) => {
73+ const data = [ ] ;
74+ gitRawCommits ( options )
75+ . on ( 'data' , chunk => data . push ( chunk . toString ( 'utf-8' ) ) )
76+ . on ( 'error' , reject )
77+ . on ( 'end' , ( ) => {
78+ resolve ( data ) ;
79+ } ) ;
80+ } ) ;
81+ }
82+
6783// Get commit messages
6884// TODO: move this to an own module
6985async function getMessages ( settings ) {
@@ -72,9 +88,14 @@ async function getMessages(settings) {
7288 if ( edit ) {
7389 const editFile = await readFile ( `.git/COMMIT_EDITMSG` ) ;
7490 return [ editFile . toString ( 'utf-8' ) ] ;
91+ } else {
92+ return await getCommits ( {
93+ from,
94+ to
95+ } ) ;
7596 }
7697
77- throw new Error ( `Reading from git history not supported yet.` ) ;
98+ // throw new Error(`Reading from git history not supported yet.`);
7899}
79100
80101// Resolve extend configs
@@ -159,6 +180,7 @@ async function main(options) {
159180 } ) ;
160181
161182 if ( ! flags . quiet ) {
183+ console . log ( `validating: ${ commit . split ( '\n' ) [ 0 ] } ` ) ;
162184 console . log (
163185 formatted
164186 . join ( '\n' )
@@ -168,6 +190,8 @@ async function main(options) {
168190 if ( report . errors . length > 0 ) {
169191 throw new Error ( formatted [ formatted . length - 1 ] ) ;
170192 }
193+
194+ console . log ( '' ) ;
171195 } ) ) ;
172196}
173197
0 commit comments