Skip to content

Commit

Permalink
Get the latest release including pre-releases (#2255)
Browse files Browse the repository at this point in the history
For GitHub projects, `GitProject.get_latest_release()` considers only
stable releases. If sync_release failed for a pre-release, the retrieved
git ref is incorrect. Fix that.

Fixes packit/specfile#325.
  • Loading branch information
nforro authored Nov 22, 2023
2 parents 64504e1 + 766094f commit ff6c0f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packit_service/worker/events/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def __init__(
def tag_name(self):
if not self._tag_name:
self._tag_name = ""
if latest_release := self.project.get_latest_release():
self._tag_name = latest_release.tag_name
if releases := self.project.get_releases():
self._tag_name = releases[0].tag_name
return self._tag_name

@property
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/test_github_fas_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_verification_successful():
flexmock(Signature).should_receive("apply_async").once()
flexmock(Pushgateway).should_receive("push").times(2).and_return()
flexmock(GithubProject).should_receive("is_private").and_return(False)
flexmock(GithubProject).should_receive("get_latest_release").and_return(None)
flexmock(GithubProject).should_receive("get_releases").and_return([])
flexmock(PackageConfigGetter).should_receive(
"get_package_config_from_repo"
).and_return(None)
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_verification_not_successful():
flexmock(Signature).should_receive("apply_async").once()
flexmock(Pushgateway).should_receive("push").times(2).and_return()
flexmock(GithubProject).should_receive("is_private").and_return(False)
flexmock(GithubProject).should_receive("get_latest_release").and_return(None)
flexmock(GithubProject).should_receive("get_releases").and_return([])
flexmock(PackageConfigGetter).should_receive(
"get_package_config_from_repo"
).and_return(None)
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_verification_incorrect_format(comment):
flexmock(Signature).should_receive("apply_async").once()
flexmock(Pushgateway).should_receive("push").times(2).and_return()
flexmock(GithubProject).should_receive("is_private").and_return(False)
flexmock(GithubProject).should_receive("get_latest_release").and_return(None)
flexmock(GithubProject).should_receive("get_releases").and_return([])
flexmock(PackageConfigGetter).should_receive(
"get_package_config_from_repo"
).and_return(None)
Expand Down Expand Up @@ -224,7 +224,7 @@ def test_verification_already_approved():
flexmock(Signature).should_receive("apply_async").once()
flexmock(Pushgateway).should_receive("push").times(2).and_return()
flexmock(GithubProject).should_receive("is_private").and_return(False)
flexmock(GithubProject).should_receive("get_latest_release").and_return(None)
flexmock(GithubProject).should_receive("get_releases").and_return([])
flexmock(PackageConfigGetter).should_receive(
"get_package_config_from_repo"
).and_return(None)
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_verification_wrong_repository():
flexmock(Pushgateway).should_receive("push").times(1).and_return()
flexmock(Signature).should_receive("apply_async").never()
flexmock(GithubProject).should_receive("is_private").and_return(False)
flexmock(GithubProject).should_receive("get_latest_release").and_return(None)
flexmock(GithubProject).should_receive("get_releases").and_return([])
flexmock(PackageConfigGetter).should_receive(
"get_package_config_from_repo"
).and_return(None)
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_verification_wrong_issue():
flexmock(Pushgateway).should_receive("push").times(1).and_return()
flexmock(Signature).should_receive("apply_async").never()
flexmock(GithubProject).should_receive("is_private").and_return(False)
flexmock(GithubProject).should_receive("get_latest_release").and_return(None)
flexmock(GithubProject).should_receive("get_releases").and_return([])
flexmock(PackageConfigGetter).should_receive(
"get_package_config_from_repo"
).and_return(None)
Expand Down Expand Up @@ -331,7 +331,7 @@ def test_verification_not_original_triggerer():
flexmock(Signature).should_receive("apply_async").once()
flexmock(Pushgateway).should_receive("push").times(2).and_return()
flexmock(GithubProject).should_receive("is_private").and_return(False)
flexmock(GithubProject).should_receive("get_latest_release").and_return(None)
flexmock(GithubProject).should_receive("get_releases").and_return([])
flexmock(PackageConfigGetter).should_receive(
"get_package_config_from_repo"
).and_return(None)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_issue_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def mock_comment(request):
tarball_url="https://foo/bar",
git_tag=flexmock(GitTag),
)
flexmock(project_class).should_receive("get_latest_release").and_return(gr)
flexmock(project_class).should_receive("get_releases").and_return([gr])
flexmock(LocalProject, refresh_the_arguments=lambda: None)
lp = flexmock(git_project=flexmock(default_branch="main"))
lp.working_dir = ""
Expand Down Expand Up @@ -313,7 +313,7 @@ def mock_repository_issue_retriggering():
project=PagureProject, fail_when_missing=False
).and_return(PackageConfig)

project.should_receive("get_latest_release").and_return(flexmock(tag_name="123"))
project.should_receive("get_releases").and_return([flexmock(tag_name="123")])
project.should_receive("get_sha_from_tag").and_return("abcdef")
project.should_receive("has_write_access").and_return(True)
db_project_object = flexmock(
Expand Down
12 changes: 5 additions & 7 deletions tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ def test_parse_issue_comment(self, github_issue_comment_propose_downstream):
assert event_object.project.full_repo_name == "packit-service/packit"
assert not event_object.base_project

flexmock(event_object.project).should_receive("get_latest_release").and_return(
flexmock(tag_name="0.5.0")
flexmock(event_object.project).should_receive("get_releases").and_return(
[flexmock(tag_name="0.5.0")]
)
flexmock(GithubProject, get_sha_from_tag=lambda tag_name: "123456")
flexmock(PackageConfigGetter).should_receive(
Expand All @@ -588,9 +588,7 @@ def test_parse_issue_comment_no_handler(self, github_issue_comment_no_handler):
assert event_object.project.full_repo_name == "packit-service/packit"
assert not event_object.base_project

flexmock(event_object.project).should_receive("get_latest_release").and_return(
None
)
flexmock(event_object.project).should_receive("get_releases").and_return([])
flexmock(GithubProject).should_receive("get_sha_from_tag").never()
flexmock(PackageConfigGetter).should_receive(
"get_package_config_from_repo"
Expand Down Expand Up @@ -625,8 +623,8 @@ def test_parse_gitlab_issue_comment(self, gitlab_issue_comment):
assert isinstance(event_object.project, GitlabProject)
assert event_object.project.full_repo_name == "testing/packit/hello-there"

flexmock(event_object.project).should_receive("get_latest_release").and_return(
flexmock(tag_name="0.5.0")
flexmock(event_object.project).should_receive("get_releases").and_return(
[flexmock(tag_name="0.5.0")]
)
flexmock(event_object.project, get_sha_from_tag=lambda tag_name: "123456")
flexmock(PackageConfigGetter).should_receive(
Expand Down

0 comments on commit ff6c0f5

Please sign in to comment.