Skip to content

Commit

Permalink
Merge pull request #889 from TomasTomecek/carry-776
Browse files Browse the repository at this point in the history
upstream git-log inside rpm %changelog

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
  • Loading branch information
softwarefactory-project-zuul[bot] committed Jul 7, 2020
2 parents b7fb08e + a2395aa commit 917e41b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
36 changes: 35 additions & 1 deletion packit/upstream.py
Expand Up @@ -409,6 +409,21 @@ def _get_archive_path_from_output(self, outputs: List[str]) -> Optional[Path]:
raise ex
return None

def get_last_tag(self) -> Optional[str]:
""" get last git-tag from the repo """
try:
last_tag = run_command(
["git", "describe", "--tags", "--abbrev=0"],
output=True,
cwd=self.local_project.working_dir,
).strip()
except PackitCommandFailedError as ex:
logger.debug(f"{ex!r}")
logger.info("Can't describe this repository, are there any git tags?")
# no tags in the git repo
return None
return last_tag

def fix_spec(self, archive: str, version: str, commit: str):
"""
In order to create a SRPM from current git checkout, we need to have the spec reference
Expand Down Expand Up @@ -456,7 +471,26 @@ def fix_spec(self, archive: str, version: str, commit: str):
f"{sanitized_current_branch}{git_desc_suffix}"
)

msg = f"- Development snapshot ({commit})"
last_tag = self.get_last_tag()
msg = ""
if last_tag:
# let's print changes b/w the last tag and now;
# ambiguous argument '0.1.0..HEAD': unknown revision or path not in the working tree.
# Use '--' to separate paths from revisions, like this
cmd = [
"git",
"log",
"--pretty=format:- %s (%an)",
f"{last_tag}..HEAD",
"--",
]
msg = run_command(
cmd, output=True, cwd=self.local_project.working_dir
).strip()
if not msg:
# no describe, no tag - just a boilerplate message w/ commit hash
# or, there were no changes b/w HEAD and last_tag, which implies last_tag == HEAD
msg = f"- Development snapshot ({commit})"
logger.debug(f"Setting Release in spec to {release!r}.")
# instead of changing version, we change Release field
# upstream projects should take care of versions
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_upstream.py
Expand Up @@ -221,6 +221,9 @@ def test_create_srpm_git_desc_release(upstream_instance):
build_srpm(srpm)
assert re.match(r".+beer-0.1.0-1\.\d+\.\w+\.fc\d{2}.src.rpm$", str(srpm))

changelog = ups.specfile.spec_content.section("%changelog")
assert "- More awesome changes (Packit Test Suite)" in changelog


def test_github_app(upstream_instance, tmp_path):
u, ups = upstream_instance
Expand All @@ -246,3 +249,8 @@ def test_github_app(upstream_instance, tmp_path):
)
in ups.config.services
)


def test_get_last_tag(upstream_instance):
u, ups = upstream_instance
assert ups.get_last_tag() == "0.1.0"
2 changes: 1 addition & 1 deletion tests/unit/test_upstream.py
@@ -1,6 +1,6 @@
import pytest

from flexmock import flexmock

from packit.actions import ActionName
from packit.local_project import LocalProject
from packit.upstream import Upstream
Expand Down

0 comments on commit 917e41b

Please sign in to comment.