Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to finding previous version from tags if not using commit messages #68

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions semantic_release/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ def changelog(**kwargs):
Generates the changelog since the last release.
"""
current_version = get_current_version()
log = generate_changelog(
get_previous_version(current_version), current_version)
if current_version is None:
raise Exception("Unable to get the current verison."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more clear? Is it a variable name? The exception string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, verison.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. That surprisingly gets me a lot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully @relekang will review and merge stuff soon, I have a PR waiting too.

" Make sure semantic_release.version_variable "
"is setup correctly")
previous_version = get_previous_version(current_version)

log = generate_changelog(previous_version, current_version)
for section in CHANGELOG_SECTIONS:
if not log[section]:
continue
Expand Down
7 changes: 5 additions & 2 deletions semantic_release/history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ def get_previous_version(version):
continue

if found_version:
if re.match(r'v?\d+.\d+.\d+', commit_message):
return commit_message.replace('v', '').strip()
matches = re.match(r'v?(\d+.\d+.\d+)', commit_message)
if matches:
return matches.group(1).strip()

return get_last_version([version, 'v{}'.format(version)])


def set_new_version(new_version):
Expand Down
15 changes: 12 additions & 3 deletions semantic_release/vcs_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re

from git import GitCommandError, Repo
from git import GitCommandError, TagObject, Repo

from .errors import GitError
from .settings import config
Expand All @@ -19,14 +19,23 @@ def get_commit_log(from_rev=None):
yield (commit.hexsha, commit.message)


def get_last_version():
def get_last_version(skip_tags=None):
"""
return last version from repo tags

:return: a string contains version number
"""
for i in sorted(repo.tags, key=lambda x: x.commit.committed_date, reverse=True):
skip_tags = skip_tags or []

def version_finder(x):
if isinstance(x.commit, TagObject):
return x.tag.tagged_date
return x.commit.committed_date

for i in sorted(repo.tags, reverse=True, key=version_finder):
if re.match('v\d+\.\d+\.\d+', i.name):
if i.name in skip_tags:
continue
return i.name[1:]


Expand Down