Skip to content

Commit 07e8aad

Browse files
INO-101: Fix generating release version name
1 parent 8cc83bd commit 07e8aad

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/SourceControl.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,17 @@ export default class SourceControl {
4545
* Return top-level commit logs for a range.
4646
* Commits which were the result of a merge are nested under `<log>.graph.merged`.
4747
*
48-
* @param {String} dir The source control workspace directory.
48+
* @param {String} workspaceDir The source control workspace directory.
4949
* @param {Object} range An object defining the range boundaries (see above)
5050
*
51-
* @return {Promsie} Resolves to a list of top-level commit objects
51+
* @return {Promise} Resolves to a list of top-level commit objects
5252
*/
5353
async getCommitLogs(workspaceDir, range) {
5454
const workspace = git(workspaceDir);
5555
if (this.slack.isEnabled()) {
5656
await this.slack.getSlackUsers()
5757
}
5858

59-
if (Object.keys(range).length < 2) {
60-
await workspace.tags((e, tags) => {
61-
console.log(tags.length)
62-
if (tags.all.length > 1) {
63-
range.from = tags.all[tags.all.length - 2]
64-
range.to = tags.all[tags.all.length - 1]
65-
} else {
66-
throw new Error('No range defined for the changelog.');
67-
}
68-
})
69-
}
70-
7159
return new Promise((resolve, reject) => {
7260

7361
const opts = {
@@ -124,7 +112,7 @@ export default class SourceControl {
124112
* reverts and confirm the diff is exactly the opposite, but that might be overkill.
125113
*
126114
* @param {Object} log - A single commit log objedt
127-
* @return {String or null} - The reverted sha or null if it is not a revert
115+
* @return {String | null} - The reverted sha or null if it is not a revert
128116
*/
129117
isRevert(log) {
130118
const oneLine = log.fullText.replace(/\n/g, ' ').trim();
@@ -280,7 +268,7 @@ export default class SourceControl {
280268
const commits = [ ...graph ];
281269

282270
commits.forEach((item) => {
283-
let { summary, fullText } = item;
271+
let { fullText } = item;
284272

285273
item.graph.merged.forEach((merged) => {
286274
// Skip reverted commits

src/cli.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { generateTemplateData, renderTemplate } from './template';
1717
import {readConfigFile} from './Config';
1818
import SourceControl from './SourceControl';
1919
import 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

Comments
 (0)