Skip to content

Commit

Permalink
Fix tag prefix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Jan 15, 2018
1 parent 7c9c175 commit 40e40fe
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion scripts/generate-test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const remote = {

async function run () {
const gitLog = await readFile(join(DATA_DIR, 'git-log.txt'), 'utf-8')
const commits = parseCommits(gitLog, remote, { tagPrefix: 'v' })
const commits = parseCommits(gitLog, remote, { tagPrefix: '' })
const releases = parseReleases(commits, remote, null, { unreleased: false, commitLimit: 3 })
await writeFile(join(DATA_DIR, 'commits.js'), 'export default ' + JSON.stringify(commits, null, 2))
await writeFile(join(DATA_DIR, 'commits-no-remote.js'), 'export default ' + JSON.stringify(commitsWithoutLinks(commits), null, 2))
Expand Down
10 changes: 8 additions & 2 deletions src/commits.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import semver from 'semver'

import { cmd, isLink } from './utils'

const COMMIT_SEPARATOR = '__AUTO_CHANGELOG_COMMIT_SEPARATOR__'
Expand Down Expand Up @@ -66,8 +68,12 @@ function parseCommit (commit, remote, options = {}) {
function getTag (refs, options) {
if (!refs) return null
for (let ref of refs.split(', ')) {
if (ref.indexOf(`tag: ${options.tagPrefix}`) === 0) {
return ref.replace('tag: ', '')
const prefix = `tag: ${options.tagPrefix}`
if (ref.indexOf(prefix) === 0) {
const version = ref.replace(prefix, '')
if (semver.valid(version)) {
return version
}
}
}
return null
Expand Down
2 changes: 1 addition & 1 deletion src/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function parseReleases (commits, remote, latestVersion, options) {
let release = newRelease(latestVersion)
const releases = []
for (let commit of commits) {
if (commit.tag && semver.valid(commit.tag)) {
if (commit.tag) {
if (release.tag || options.unreleased) {
releases.push({
...release,
Expand Down
6 changes: 3 additions & 3 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DEFAULT_OPTIONS = {
template: 'compact',
remote: 'origin',
commitLimit: 3,
tagPrefix: 'v'
tagPrefix: ''
}

const PACKAGE_OPTIONS_KEY = 'auto-changelog'
Expand All @@ -32,7 +32,7 @@ function getOptions (argv, pkg) {
.option('--issue-pattern [regex]', `override regex pattern for issues in commit messages`)
.option('--ignore-commit-pattern [regex]', `pattern to ignore when parsing commits`)
.option('--starting-commit [hash]', `starting commit to use for changelog generation`)
.option('--tag-prefix [prefix]', `prefix used in version tags, default: ${DEFAULT_OPTIONS.tagPrefix}`)
.option('--tag-prefix [prefix]', `prefix used in version tags`)
.version(version)
.parse(argv)

Expand Down Expand Up @@ -60,7 +60,7 @@ function getLatestVersion (options, pkg) {
return options.latestVersion
}
if (options.package) {
return options.tagPrefix + pkg.version
return `v${pkg.version}`
}
return null
}
Expand Down
2 changes: 1 addition & 1 deletion test/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getFixes = __get__('getFixes')
const getMerge = __get__('getMerge')

const options = {
tagPrefix: 'v'
tagPrefix: ''
}

describe('fetchCommits', () => {
Expand Down

0 comments on commit 40e40fe

Please sign in to comment.