Skip to content

Commit

Permalink
✨ add checks if correct semver version
Browse files Browse the repository at this point in the history
  • Loading branch information
bpetetot committed Oct 14, 2018
1 parent a11ed49 commit 66c3baa
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

<a name="0.0.1"></a>
## 0.0.1 (2018-10-14)
<a name="next"></a>
## next

### Added

Expand Down Expand Up @@ -50,7 +50,7 @@
### Fixed

- :bug: Fix gitmoji mapping ([#20](https://github.com/frinyvonnick/gitmoji-changelog/issues/20)) ([9561914](https://github.com/frinyvonnick/gitmoji-changelog/commit/95619149e7ce7d26dcb4f1837a8c8bf351b1cb1c))
- :bug: set date for release except &#x27;next&#x27; ([1b970cb](https://github.com/frinyvonnick/gitmoji-changelog/commit/1b970cb79b397f27844b41a615372f263d220e33))
- :bug: set date for release except &#x27;next&#x27; ([a11ed49](https://github.com/frinyvonnick/gitmoji-changelog/commit/a11ed49ed62258115985f3fa9c8856c9fae96e07))
- :green_heart: Set up travis configuration ([dda9b28](https://github.com/frinyvonnick/gitmoji-changelog/commit/dda9b287989c1ca2e9513c4a5a4a3d1b6749e816))
- :green_heart: Ignore node_modules in linter ([802c0f7](https://github.com/frinyvonnick/gitmoji-changelog/commit/802c0f7dc29508876c6b4d178bbcc8274ee308b5))

Expand Down
1 change: 1 addition & 0 deletions packages/gitmoji-changelog-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"lodash": "^4.17.11",
"normalize-package-data": "^2.4.0",
"read-pkg-up": "^4.0.0",
"semver": "^5.6.0",
"semver-compare": "^1.0.0",
"signale": "^1.3.0",
"split-lines": "^2.0.0",
Expand Down
28 changes: 18 additions & 10 deletions packages/gitmoji-changelog-core/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const semver = require('semver')
const gitRawCommits = require('git-raw-commits')
const gitSemverTags = require('git-semver-tags')
const semverCompare = require('semver-compare')
Expand Down Expand Up @@ -49,11 +50,11 @@ function makeGroups(commits) {
.filter(group => group.commits.length)
}

function getVersionFromTagName(tagName) {
if (tagName && tagName.startsWith('v')) {
return tagName.slice(1, tagName.length)
}
return tagName
function sanitizeVersion(version) {
return semver.valid(version, {
loose: false,
includePrerelease: true,
})
}

async function generateChanges({ from, to, version }) {
Expand All @@ -74,7 +75,7 @@ async function generateTagsChanges(tags) {
const changes = await generateChanges({
from: previousTag,
to: tag,
version: getVersionFromTagName(tag),
version: sanitizeVersion(tag),
})
previousTag = tag
return changes
Expand All @@ -88,6 +89,14 @@ async function generateChangelog(options = {}) {

const packageInfo = await getPackageInfo()

let version = release === 'from-package' ? packageInfo.version : release
if (version && version !== 'next') {
if (!semver.valid(version)) {
throw new Error(`${version} is not a valid semver version.`)
}
version = sanitizeVersion(version)
}

let changes = []

const tags = await gitSemverTagsAsync()
Expand All @@ -97,11 +106,10 @@ async function generateChangelog(options = {}) {
changes = await generateTagsChanges(tags)
}

const specificVersion = release === 'from-package' ? packageInfo.version : release
if (mode !== 'init' && specificVersion) {
if (mode !== 'init' && version) {
const lastChanges = await generateChanges({
from: lastTag,
version: specificVersion,
version: version,
})
changes.push(lastChanges)
}
Expand All @@ -112,7 +120,7 @@ async function generateChangelog(options = {}) {
meta: {
package: packageInfo,
repository,
lastVersion: getVersionFromTagName(lastTag),
lastVersion: sanitizeVersion(lastTag),
},
changes,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gitmoji-changelog-markdown/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Markdown converter', () => {
<a name="1.0.0"></a>
## 1.0.0 - 2018-08-28
## 1.0.0 (2018-08-28)
### Added
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3849,6 +3849,10 @@ semver-compare@^1.0.0:
version "5.5.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.1.tgz#7dfdd8814bdb7cabc7be0fb1d734cfb66c940477"

semver@^5.6.0:
version "5.6.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004"

set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down

0 comments on commit 66c3baa

Please sign in to comment.