Fix error handling on confpy script
All checks were successful
gl/check check status: success (2be2e7b88db530722c886f9476df6479e6d6b310)
All checks were successful
gl/check check status: success (2be2e7b88db530722c886f9476df6479e6d6b310)
This commit is contained in:
parent
50ed3a6611
commit
2be2e7b88d
@ -44,6 +44,7 @@ def process_repositories(args, service):
|
|||||||
url_to = None
|
url_to = None
|
||||||
target_repo = None
|
target_repo = None
|
||||||
git_fqdn = None
|
git_fqdn = None
|
||||||
|
error_list = []
|
||||||
|
|
||||||
env = Environment(
|
env = Environment(
|
||||||
loader=PackageLoader("otc_metadata"), autoescape=select_autoescape()
|
loader=PackageLoader("otc_metadata"), autoescape=select_autoescape()
|
||||||
@ -75,7 +76,11 @@ def process_repositories(args, service):
|
|||||||
repo_url = f"git@github.com:/{repo['repo']}"
|
repo_url = f"git@github.com:/{repo['repo']}"
|
||||||
else:
|
else:
|
||||||
logging.error(f"Repository type {repo['type']} is not supported")
|
logging.error(f"Repository type {repo['type']} is not supported")
|
||||||
exit(1)
|
error_list.append({
|
||||||
|
"error": f"Repository type {repo['type']} is not supported",
|
||||||
|
"repo": repo['repo']
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
|
||||||
if repo_dir.exists():
|
if repo_dir.exists():
|
||||||
logging.debug(f"Repository {repo} already checked out")
|
logging.debug(f"Repository {repo} already checked out")
|
||||||
@ -87,13 +92,22 @@ def process_repositories(args, service):
|
|||||||
except exc.InvalidGitRepositoryError:
|
except exc.InvalidGitRepositoryError:
|
||||||
logging.error("Existing repository checkout is bad")
|
logging.error("Existing repository checkout is bad")
|
||||||
repo_dir.rmdir()
|
repo_dir.rmdir()
|
||||||
|
except Exception as e:
|
||||||
|
error_list.append({
|
||||||
|
"error": e,
|
||||||
|
"repo": repo['repo']
|
||||||
|
})
|
||||||
|
|
||||||
if not repo_dir.exists():
|
if not repo_dir.exists():
|
||||||
try:
|
try:
|
||||||
git_repo = Repo.clone_from(repo_url, repo_dir, branch="main")
|
git_repo = Repo.clone_from(repo_url, repo_dir, branch="main")
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.error(f"Error cloning repository {repo_url}")
|
logging.error(f"Error cloning repository {repo_url}")
|
||||||
return
|
error_list.append({
|
||||||
|
"error": f"Error cloning repository {repo_url}",
|
||||||
|
"repo": repo['repo']
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
|
||||||
if repo["environment"] == args.target_environment:
|
if repo["environment"] == args.target_environment:
|
||||||
url_to = repo_url
|
url_to = repo_url
|
||||||
@ -116,11 +130,19 @@ def process_repositories(args, service):
|
|||||||
repo_to.delete_head(f"refs/heads/{args.branch_name}", force=True)
|
repo_to.delete_head(f"refs/heads/{args.branch_name}", force=True)
|
||||||
except exc.GitCommandError as e:
|
except exc.GitCommandError as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
error_list.append({
|
||||||
|
"error": e,
|
||||||
|
"repo": target_repo['repo']
|
||||||
|
})
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
new_branch = repo_to.create_head(branch_name, "main")
|
new_branch = repo_to.create_head(branch_name, "main")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning(f"Skipping service {service} due to {e}")
|
logging.warning(f"Skipping service {service} due to {e}")
|
||||||
|
error_list.append({
|
||||||
|
"error": e,
|
||||||
|
"repo": target_repo['repo']
|
||||||
|
})
|
||||||
return
|
return
|
||||||
new_branch.checkout()
|
new_branch.checkout()
|
||||||
|
|
||||||
@ -283,7 +305,13 @@ def process_repositories(args, service):
|
|||||||
push_args = ["--set-upstream", "origin", branch_name]
|
push_args = ["--set-upstream", "origin", branch_name]
|
||||||
if args.force_push:
|
if args.force_push:
|
||||||
push_args.append("--force")
|
push_args.append("--force")
|
||||||
|
try:
|
||||||
repo_to.git.push(*push_args)
|
repo_to.git.push(*push_args)
|
||||||
|
except Exception as e:
|
||||||
|
error_list.append({
|
||||||
|
"error": e,
|
||||||
|
"repo": repo['repo']
|
||||||
|
})
|
||||||
if "github" in url_to:
|
if "github" in url_to:
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
args=["gh", "pr", "create", "-f"], cwd=copy_to, check=False
|
args=["gh", "pr", "create", "-f"], cwd=copy_to, check=False
|
||||||
@ -297,6 +325,9 @@ def process_repositories(args, service):
|
|||||||
head=branch_name,
|
head=branch_name,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
if len(error_list) != 0:
|
||||||
|
logging.error("The following errors have happened:")
|
||||||
|
logging.error(error_list)
|
||||||
|
|
||||||
|
|
||||||
def open_pr(args, repository, pr_data):
|
def open_pr(args, repository, pr_data):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user