From 43c5909a38afabe335a535ad4d851b1d1cb1e623 Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Tue, 6 Jun 2017 22:20:45 -0700 Subject: [PATCH 1/4] feat: Be a bit more forgiving to find previous tags Now grabs the previous version from tag names if it can't find it in the commit --- semantic_release/cli.py | 9 +++++++-- semantic_release/history/__init__.py | 7 +++++-- semantic_release/vcs_helpers.py | 10 +++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/semantic_release/cli.py b/semantic_release/cli.py index 7d9291d80..93e25cf8d 100644 --- a/semantic_release/cli.py +++ b/semantic_release/cli.py @@ -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." + " 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 diff --git a/semantic_release/history/__init__.py b/semantic_release/history/__init__.py index 810f42fa4..abe821cf0 100644 --- a/semantic_release/history/__init__.py +++ b/semantic_release/history/__init__.py @@ -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): diff --git a/semantic_release/vcs_helpers.py b/semantic_release/vcs_helpers.py index 74eb699a8..2c0ab56bd 100644 --- a/semantic_release/vcs_helpers.py +++ b/semantic_release/vcs_helpers.py @@ -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 @@ -19,14 +19,18 @@ def get_commit_log(from_rev=None): yield (commit.hexsha, commit.message) -def get_last_version(): +def get_last_version(skipTags=[]): """ 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): + for i in sorted(repo.tags, reverse=True, key=lambda x: x.tag.tagged_date + if isinstance(x.commit,TagObject) + else x.commit.committed_date): if re.match('v\d+\.\d+\.\d+', i.name): + if i.name in skipTags: + continue return i.name[1:] From d4a74551397c0a0408fe9d6ef3d828ebe8947fbf Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Tue, 6 Jun 2017 22:28:36 -0700 Subject: [PATCH 2/4] quantifiedcode and flake8 fixes --- semantic_release/vcs_helpers.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/semantic_release/vcs_helpers.py b/semantic_release/vcs_helpers.py index 2c0ab56bd..da8860474 100644 --- a/semantic_release/vcs_helpers.py +++ b/semantic_release/vcs_helpers.py @@ -19,17 +19,22 @@ def get_commit_log(from_rev=None): yield (commit.hexsha, commit.message) -def get_last_version(skipTags=[]): +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, reverse=True, key=lambda x: x.tag.tagged_date - if isinstance(x.commit,TagObject) - else x.commit.committed_date): + 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 skipTags: + if i.name in skip_tags: continue return i.name[1:] From 7d0677ac7884fd4c1367ac17415718a54af5bacc Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Tue, 10 Apr 2018 09:46:29 -0700 Subject: [PATCH 3/4] Update cli.py --- semantic_release/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic_release/cli.py b/semantic_release/cli.py index 93e25cf8d..c72ffdcbd 100644 --- a/semantic_release/cli.py +++ b/semantic_release/cli.py @@ -79,7 +79,7 @@ def changelog(**kwargs): """ current_version = get_current_version() if current_version is None: - raise Exception("Unable to get the current verison." + raise Exception("Unable to get the current version." " Make sure semantic_release.version_variable " "is setup correctly") previous_version = get_previous_version(current_version) From 32f0de2567481b6aed71c5c8b6c77606e41e6da4 Mon Sep 17 00:00:00 2001 From: Gavin Mogan Date: Tue, 10 Apr 2018 14:03:10 -0700 Subject: [PATCH 4/4] Switch to ImproperConfigurationError --- semantic_release/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic_release/cli.py b/semantic_release/cli.py index c72ffdcbd..03b84fbf2 100644 --- a/semantic_release/cli.py +++ b/semantic_release/cli.py @@ -79,7 +79,7 @@ def changelog(**kwargs): """ current_version = get_current_version() if current_version is None: - raise Exception("Unable to get the current version." + raise ImproperConfigurationError("Unable to get the current version." " Make sure semantic_release.version_variable " "is setup correctly") previous_version = get_previous_version(current_version)