Skip to content

Commit

Permalink
🐛 Prevent having right commits by version (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick authored Oct 25, 2018
1 parent 9b0eb6b commit de06319
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
29 changes: 16 additions & 13 deletions packages/gitmoji-changelog-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,22 @@ async function generateVersion({ from, to, version }) {
}

async function generateVersions(tags) {
let previousTag = ''

return Promise.all(tags.map(async tag => {
const changes = await generateVersion({
from: previousTag,
to: tag,
version: sanitizeVersion(tag),
})
previousTag = tag
return changes
})).then((changes) => {
return changes.sort((c1, c2) => semverCompare(c2.version, c1.version))
})
let nextTag = ''

return Promise.all(
tags
.map(tag => {
const params = {
from: tag,
to: nextTag,
version: sanitizeVersion(tag),
}
nextTag = tag
return params
})
.map(generateVersion)
)
.then(changes => changes.sort((c1, c2) => semverCompare(c2.version, c1.version)))
}

async function generateChangelog(options = {}) {
Expand Down
11 changes: 11 additions & 0 deletions packages/gitmoji-changelog-core/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ describe('changelog', () => {
}
expect(message).toBeTruthy()
})

it('should get previous tag in from', async () => {
mockGroups()

gitSemverTags.mockImplementation(cb => cb(null, ['v1.0.1', 'v1.0.0']))

await generateChangelog({ mode: 'init' })

expect(gitRawCommits).toHaveBeenCalledWith(expect.objectContaining({ from: 'v1.0.1', to: '' }))
expect(gitRawCommits).toHaveBeenCalledWith(expect.objectContaining({ from: 'v1.0.0', to: 'v1.0.1' }))
})
})

jest.mock('git-raw-commits')
Expand Down

0 comments on commit de06319

Please sign in to comment.