Skip to content

Commit 6b96faf

Browse files
committed
koji: Log exception on missing remote branches
FTR, I introduced the check in a previous commit, and removed the tuple containing the results because it is useless and not working when there is no result, this change is an updated version of the test to trigger and exception which will be ignored and attempt to look for commit in other branches, a log may be printed to help trouble shoot. Fix redefined-builtin mistake (BTW I noticed similar mistakes elsewhere to be fixed in later PR) Fix indantation mistake from previous commit Signed-off-by: Philippe Coval <philippe.coval@vates.tech>
1 parent 4dcf9ab commit 6b96faf

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

scripts/koji/koji_build.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ def check_commit_is_available_remotely(dirpath, hash, target, warn):
5656
supported_branches = PROTECTED_TARGETS.get(target)
5757
if supported_branches:
5858
for branch in supported_branches:
59-
if is_remote_branch_commit(dirpath, hash, branch):
60-
logging.debug(f"commit {hash} is on top of branch {branch} (target: {target})")
61-
break
59+
try:
60+
if is_remote_branch_commit(dirpath, hash, branch):
61+
logging.debug(f"commit {hash} is on top of branch {branch} (target: {target})")
62+
break
63+
except Exception as e:
64+
logging.debug(f"{e} Ignoring")
6265
else:
6366
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}.")
67+
f"This is required when using the protected target {target}.")
6568
else:
6669
raise Exception(f"Protected target {target} has no allowed branches.")
6770
except Exception as e:
@@ -157,8 +160,10 @@ def push_bumped_release(git_repo, target, test_build_id, pre_build_id):
157160

158161
def is_remote_branch_commit(git_repo, sha, branch):
159162
with cd(git_repo):
160-
list = subprocess.check_output(['git', 'ls-remote', 'origin', f'refs/heads/{branch}']).decode().strip().split()
161-
remote_sha = list[0] if list else None
163+
references = subprocess.check_output(['git', 'ls-remote', 'origin', f'refs/heads/{branch}']).decode().strip().split()
164+
if not references:
165+
raise Exception(f'Missing remote branch "{branch}"')
166+
remote_sha = references[0]
162167
return sha == remote_sha
163168

164169
def build_id_of(name, candidate):

0 commit comments

Comments
 (0)