@@ -17,6 +17,7 @@ import { generateTemplateData, renderTemplate } from './template';
1717import { readConfigFile } from './Config' ;
1818import SourceControl from './SourceControl' ;
1919import Jira from './Jira' ;
20+ import git from "simple-git" ;
2021
2122/**
2223 * Parse command line arguments
@@ -67,10 +68,11 @@ async function runProgram() {
6768 gitPath = path . resolve ( gitPath ) ;
6869
6970 const config = readConfigFile ( gitPath ) ;
71+ config . gitPath = gitPath ;
7072 const jira = new Jira ( config ) ;
7173 const source = new SourceControl ( config ) ;
7274
73- const range = getRangeObject ( config , options ) ;
75+ const range = await getRangeObject ( config , options ) ;
7476
7577 // Release flag used, but no name passed
7678 if ( options . release === true ) {
@@ -182,9 +184,10 @@ export function parseRange(rangeStr) {
182184 * Construct the range object from the CLI arguments and config
183185 *
184186 * @param {Object } config - The config object provided by Config.getConfigForPath
187+ * @param {Object } options - Command line arguments parsed in options object
185188 * @return {Object }
186189 */
187- function getRangeObject ( config , options ) {
190+ async function getRangeObject ( config , options ) {
188191 const range = { } ;
189192 const defaultRange = ( config . sourceControl && config . sourceControl . defaultRange ) ? config . sourceControl . defaultRange : { } ;
190193
@@ -203,9 +206,19 @@ function getRangeObject(config, options) {
203206 Object . assign ( range , defaultRange ) ;
204207 }
205208
206- // if (!Object.keys(range).length){
207- // throw new Error('No range defined for the changelog.');
208- // }
209+ if ( Object . keys ( range ) . length < 2 ) {
210+ const workspace = git ( config . gitPath ) ;
211+ await workspace . tags ( ( e , tags ) => {
212+ if ( tags . all . length > 1 ) {
213+ range . from = tags . all [ tags . all . length - 2 ]
214+ range . to = tags . all [ tags . all . length - 1 ]
215+ }
216+ } )
217+ }
218+
219+ if ( ! Object . keys ( range ) . length ) {
220+ throw new Error ( 'No range defined for the changelog.' ) ;
221+ }
209222
210223 // Ensure symmetric is explicitly set
211224 range . symmetric = ! ! range . symmetric ;
0 commit comments