Skip to content

Commit

Permalink
♻️ Make various changes from review (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick authored Jul 17, 2019
1 parent 8df6705 commit 7d1aabf
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/gitmoji-changelog-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const gitSemverTags = require('git-semver-tags')
const semverCompare = require('semver-compare')
const through = require('through2')
const concat = require('concat-stream')
const { isEmpty } = require('lodash')
const { get, isEmpty } = require('lodash')
const { promisify } = require('util')

const { parseCommit } = require('./parser')
Expand All @@ -16,7 +16,7 @@ const gitSemverTagsAsync = promisify(gitSemverTags)

const COMMIT_FORMAT = '%n%H%n%an%n%cI%n%s%n%b'
const HEAD = ''
const START = ''
const TAIL = ''

function getCommits(from, to) {
return new Promise((resolve) => {
Expand Down Expand Up @@ -106,11 +106,9 @@ async function generateVersions({
groupSimilarCommits,
}) {
let nextTag = HEAD
const targetVersion = hasNext ? 'next' : sanitizeVersion(release)
const changes = await Promise.all(tags.map(async tag => {
let version = sanitizeVersion(nextTag)
if (!nextTag) {
version = hasNext ? 'next' : release
}
const version = sanitizeVersion(nextTag) || targetVersion
const from = tag
const to = nextTag
nextTag = tag
Expand All @@ -137,18 +135,18 @@ async function generateChangelog(options = {}) {

if (mode === 'init') {
lastVersion = release
tagsToProcess = [...tagsToProcess, START]
tagsToProcess = [...tagsToProcess, TAIL]
} else {
const { meta } = options
lastVersion = meta && meta.lastVersion ? meta.lastVersion : undefined
lastVersion = get(meta, 'lastVersion')

if (lastVersion !== undefined) {
const lastVersionIndex = tagsToProcess.findIndex(tag => semver.eq(tag, lastVersion))
tagsToProcess.splice(lastVersionIndex + 1)
}

if (hasNext && isEmpty(tagsToProcess)) {
tagsToProcess.push('')
tagsToProcess.push(HEAD)
}
}

Expand Down

0 comments on commit 7d1aabf

Please sign in to comment.