@@ -155,6 +155,26 @@ def is_remote_branch_commit(git_repo, sha, branch):
155155 )
156156 return sha == remote_sha
157157
158+ def build_id_of (name , candidate ):
159+ if candidate is None :
160+ return None
161+
162+ length = len (candidate )
163+ if length > 16 :
164+ logging .error (f"The { name } build id must be at most 16 characters long, it's { length } characters long" )
165+ exit (1 )
166+
167+ invalid_chars = any (re .match (r'[a-zA-Z0-9]' , char ) is None for char in candidate )
168+
169+ if invalid_chars :
170+ pp_invalid = '' .join ("^" if re .match (r'[a-zA-Z0-9]' , char ) is None else " " for char in candidate )
171+ logging .error (f"The { name } build id must only contain letters and digits:" )
172+ logging .error (f" { candidate } " )
173+ logging .error (f" { pp_invalid } " )
174+ exit (1 )
175+
176+ return candidate
177+
158178def main ():
159179 parser = argparse .ArgumentParser (
160180 description = 'Build a package or chain-build several from local git repos for RPM sources'
@@ -182,17 +202,13 @@ def main():
182202 git_repos = [os .path .abspath (check_dir (d )) for d in args .git_repos ]
183203 is_scratch = args .scratch
184204 is_nowait = args .nowait
185- test_build = args .test_build
186- pre_build = args .pre_build
205+
206+ test_build = build_id_of ("test" , args .test_build )
207+ pre_build = build_id_of ("pre" , args .pre_build )
208+
187209 if test_build and pre_build :
188210 logging .error ("--pre-build and --test-build can't be used together" )
189211 exit (1 )
190- if test_build is not None and re .match ('^[a-zA-Z0-9]{1,16}$' , test_build ) is None :
191- logging .error ("The test build id must be 16 characters long maximum and only contain letters and digits" )
192- exit (1 )
193- if pre_build is not None and re .match ('^[a-zA-Z0-9]{1,16}$' , pre_build ) is None :
194- logging .error ("The pre build id must be 16 characters long maximum and only contain letters and digits" )
195- exit (1 )
196212
197213 if len (git_repos ) > 1 and is_scratch :
198214 parser .error ("--scratch is not compatible with chained builds." )
0 commit comments