Skip to content

Commit 2334a23

Browse files
rzrydirson
andauthored
koji: Rewrite available test using for-else statements
This saves an extra variable but could make it harder to read. https://docs.python.org/3/tutorial/controlflow.html#else-clauses-on-loops Co-authored-by: Yann Dirson <yann.dirson@vates.tech> Signed-off-by: Philippe Coval <rzr@users.sf.net>
1 parent 4ba0323 commit 2334a23

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/koji/koji_build.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ def check_commit_is_available_remotely(dirpath, hash, target, warn):
5353
if target is not None and re.match(r'v\d+\.\d+-u-.+', target):
5454
raise Exception("Building with a user target requires using --pre-build or --test-build.\n")
5555
try:
56-
available = False
5756
supported_branches = PROTECTED_TARGETS.get(target)
5857
if supported_branches:
5958
for branch in supported_branches:
60-
available = is_remote_branch_commit(dirpath, hash, branch)
61-
if available:
59+
if is_remote_branch_commit(dirpath, hash, branch):
6260
logging.debug(f"commit {hash} is on top of branch {branch} (target: {target})")
6361
break
64-
if not available:
65-
raise Exception(f"The current commit is not the last commit of any remote branches {supported_branches}.\n"
66-
f"This is required when using the protected target {target}.\n")
62+
else:
63+
raise Exception(f"The current commit is not the last commit of any remote branches {supported_branches}.\n"
64+
f"This is required when using the protected target {target}.")
65+
else:
66+
raise Exception(f"Protected target {target} has no allowed branches.")
6767
except Exception as e:
6868
if warn:
6969
print(f"warning: {e}", flush=True)

0 commit comments

Comments
 (0)