Skip to content

Commit

Permalink
fix: add get_formatted_tag helper instead of hardcoded v-prefix in th…
Browse files Browse the repository at this point in the history
…e git tags
  • Loading branch information
perewall authored and relekang committed Aug 17, 2021
1 parent 0f6681e commit 1a354c8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
5 changes: 3 additions & 2 deletions semantic_release/changelog/compare.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional

from ..settings import config
from ..vcs_helpers import get_repository_owner_and_name
from ..vcs_helpers import get_repository_owner_and_name, get_formatted_tag


def get_github_compare_url(from_version: str, to_version: str) -> str:
Expand All @@ -14,7 +14,8 @@ def get_github_compare_url(from_version: str, to_version: str) -> str:
"""
owner, name = get_repository_owner_and_name()
return (
f"https://github.com/{owner}/{name}" f"/compare/v{from_version}...v{to_version}"
f"https://github.com/{owner}/{name}/compare/"
f"{get_formatted_tag(from_version)}...{get_formatted_tag(to_version)}"
)


Expand Down
4 changes: 2 additions & 2 deletions semantic_release/history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ..errors import ImproperConfigurationError
from ..helpers import LoggedFunction
from ..settings import config
from ..vcs_helpers import get_commit_log, get_last_version
from ..vcs_helpers import get_commit_log, get_last_version, get_formatted_tag
from .logs import evaluate_version_bump # noqa

from .parser_angular import parse_commit_message as angular_parser # noqa isort:skip
Expand Down Expand Up @@ -265,7 +265,7 @@ def get_previous_version(version: str) -> Optional[str]:
logger.debug(f"Version matches regex {commit_message}")
return matches.group(1).strip()

return get_last_version([version, f"v{version}"])
return get_last_version([version, get_formatted_tag(version)])


@LoggedFunction(logger)
Expand Down
4 changes: 2 additions & 2 deletions semantic_release/history/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def evaluate_version_bump(current_version: str, force: str = None) -> Optional[s
changes = []
commit_count = 0

for _hash, commit_message in get_commit_log(f"v{current_version}"):
for _hash, commit_message in get_commit_log(current_version):
if commit_message.startswith(current_version):
# Stop once we reach the current version
# (we are looping in the order of newest -> oldest)
Expand Down Expand Up @@ -95,7 +95,7 @@ def generate_changelog(from_version: str, to_version: str = None) -> dict:

rev = None
if from_version:
rev = f"v{from_version}"
rev = from_version

found_the_release = to_version is None
for _hash, commit_message in get_commit_log(rev):
Expand Down
7 changes: 4 additions & 3 deletions semantic_release/hvcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .errors import ImproperConfigurationError
from .helpers import LoggedFunction, build_requests_session
from .settings import config
from .vcs_helpers import get_formatted_tag

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -256,7 +257,7 @@ def post_release_changelog(
:return: The status of the request
"""
tag = f"v{version}"
tag = get_formatted_tag(version)
logger.debug(f"Attempting to create release for {tag}")
success = Github.create_release(owner, repo, tag, changelog)

Expand Down Expand Up @@ -326,7 +327,7 @@ def upload_dists(cls, owner: str, repo: str, version: str, path: str) -> bool:
"""

# Find the release corresponding to this version
release_id = Github.get_release(owner, repo, f"v{version}")
release_id = Github.get_release(owner, repo, get_formatted_tag(version))
if not release_id:
logger.debug("No release found to upload assets to")
return False
Expand Down Expand Up @@ -410,7 +411,7 @@ def post_release_changelog(
:return: The status of the request
"""
ref = "v" + version
ref = get_formatted_tag(version)
gl = gitlab.Gitlab(Gitlab.api_url(), private_token=Gitlab.token())
gl.auth()
try:
Expand Down
10 changes: 8 additions & 2 deletions semantic_release/vcs_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ def function_wrapper(*args, **kwargs):
return function_wrapper


def get_formatted_tag(version):
"""Get the version, formatted with `tag_format` config option"""
tag_format = config.get("tag_format")
return tag_format.format(version=version)


@check_repo
def get_commit_log(from_rev=None):
"""Yield all commit messages from last to first."""
rev = None
if from_rev:
from_rev = get_formatted_tag(from_rev)
try:
repo.commit(from_rev)
rev = f"...{from_rev}"
Expand Down Expand Up @@ -200,8 +207,7 @@ def tag_new_version(version: str):
:param version: The version number used in the tag as a string.
"""
tag_format = config.get("tag_format")
tag = tag_format.format(version=version)
tag = get_formatted_tag(version)
return repo.git.tag("-a", tag, m=tag)


Expand Down

0 comments on commit 1a354c8

Please sign in to comment.