Skip to content

Commit

Permalink
Account for a dist-git branch without a candidate tag (#2486)
Browse files Browse the repository at this point in the history
Account for a dist-git branch without a candidate tag

Such case should never really happen but it should be handled.
Related to #2379.
Merge after packit/packit#2372.

Reviewed-by: František Lachman <[email protected]>
Reviewed-by: Laura Barcziová
Reviewed-by: Maja Massarini
  • Loading branch information
softwarefactory-project-zuul[bot] authored Jul 31, 2024
2 parents ea01928 + 04237d7 commit a775027
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
4 changes: 3 additions & 1 deletion packit_service/worker/handlers/bodhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ def get_builds_in_sidetag(self, dist_git_branch: str) -> Tuple[str, List[str]]:
missing = dependencies - tagged_packages
raise PackitException(f"Missing dependencies for Bodhi update: {missing}")

candidate_tag = self.koji_helper.get_candidate_tag(dist_git_branch)
if not (candidate_tag := self.koji_helper.get_candidate_tag(dist_git_branch)):
raise PackitException(f"Failed to get candidate tag for {dist_git_branch}")

stable_tags = self.koji_helper.get_stable_tags(candidate_tag)

nvrs = []
Expand Down
41 changes: 22 additions & 19 deletions packit_service/worker/handlers/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,33 @@ class GetKojiBuildDataFromKojiService(Config, GetKojiBuildData):
_koji_helper: Optional[KojiHelper] = None

@property
def koji_helper(self):
def koji_helper(self) -> KojiHelper:
if not self._koji_helper:
self._koji_helper = KojiHelper()
return self._koji_helper

def _get_latest_build(self) -> dict:
if not (
candidate_tag := self.koji_helper.get_candidate_tag(self._dist_git_branch)
):
raise PackitException(
f"Failed to get candidate tag for {self._dist_git_branch}"
)
build = self.koji_helper.get_latest_build_in_tag(
package=self.project.repo,
tag=candidate_tag,
)
if not build:
raise PackitException(
f"No build found for package={self.project.repo} "
f"and branch={self._dist_git_branch}"
)
return build

@property
def build(self):
def build(self) -> dict:
if not self._build:
self._build = self.koji_helper.get_latest_build_in_tag(
package=self.project.repo,
tag=self.koji_helper.get_candidate_tag(self._dist_git_branch),
)
if not self._build:
raise PackitException(
f"No build found for package={self.project.repo} and tag={self.dist_git_branch}"
)
self._build = self._get_latest_build()
return self._build

@property
Expand Down Expand Up @@ -292,15 +303,7 @@ def _dist_git_branch(self) -> str:
@property
def build(self):
# call it every time since dist_git_branch reference can change
build = self.koji_helper.get_latest_build_in_tag(
package=self.project.repo,
tag=self.koji_helper.get_candidate_tag(self._dist_git_branch),
)
if not build:
raise PackitException(
f"No build found for package={self.project.repo} and tag={self.dist_git_branch}"
)
return build
return self._get_latest_build()

@property
def num_of_branches(self):
Expand Down

0 comments on commit a775027

Please sign in to comment.