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:
		@ -44,6 +44,7 @@ def process_repositories(args, service):
 | 
			
		||||
    url_to = None
 | 
			
		||||
    target_repo = None
 | 
			
		||||
    git_fqdn = None
 | 
			
		||||
    error_list = []
 | 
			
		||||
 | 
			
		||||
    env = Environment(
 | 
			
		||||
        loader=PackageLoader("otc_metadata"), autoescape=select_autoescape()
 | 
			
		||||
@ -75,7 +76,11 @@ def process_repositories(args, service):
 | 
			
		||||
            repo_url = f"git@github.com:/{repo['repo']}"
 | 
			
		||||
        else:
 | 
			
		||||
            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():
 | 
			
		||||
            logging.debug(f"Repository {repo} already checked out")
 | 
			
		||||
@ -87,13 +92,22 @@ def process_repositories(args, service):
 | 
			
		||||
            except exc.InvalidGitRepositoryError:
 | 
			
		||||
                logging.error("Existing repository checkout is bad")
 | 
			
		||||
                repo_dir.rmdir()
 | 
			
		||||
            except Exception as e:
 | 
			
		||||
                error_list.append({
 | 
			
		||||
                    "error": e,
 | 
			
		||||
                    "repo": repo['repo']
 | 
			
		||||
                })
 | 
			
		||||
 | 
			
		||||
        if not repo_dir.exists():
 | 
			
		||||
            try:
 | 
			
		||||
                git_repo = Repo.clone_from(repo_url, repo_dir, branch="main")
 | 
			
		||||
            except Exception:
 | 
			
		||||
                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:
 | 
			
		||||
            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)
 | 
			
		||||
        except exc.GitCommandError as e:
 | 
			
		||||
            print(e)
 | 
			
		||||
            error_list.append({
 | 
			
		||||
                "error": e,
 | 
			
		||||
                "repo": target_repo['repo']
 | 
			
		||||
            })
 | 
			
		||||
            pass
 | 
			
		||||
    try:
 | 
			
		||||
        new_branch = repo_to.create_head(branch_name, "main")
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        logging.warning(f"Skipping service {service} due to {e}")
 | 
			
		||||
        error_list.append({
 | 
			
		||||
            "error": e,
 | 
			
		||||
            "repo": target_repo['repo']
 | 
			
		||||
        })
 | 
			
		||||
        return
 | 
			
		||||
    new_branch.checkout()
 | 
			
		||||
 | 
			
		||||
@ -283,7 +305,13 @@ def process_repositories(args, service):
 | 
			
		||||
    push_args = ["--set-upstream", "origin", branch_name]
 | 
			
		||||
    if args.force_push:
 | 
			
		||||
        push_args.append("--force")
 | 
			
		||||
    repo_to.git.push(*push_args)
 | 
			
		||||
    try:
 | 
			
		||||
        repo_to.git.push(*push_args)
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        error_list.append({
 | 
			
		||||
            "error": e,
 | 
			
		||||
            "repo": repo['repo']
 | 
			
		||||
        })
 | 
			
		||||
    if "github" in url_to:
 | 
			
		||||
        subprocess.run(
 | 
			
		||||
            args=["gh", "pr", "create", "-f"], cwd=copy_to, check=False
 | 
			
		||||
@ -297,6 +325,9 @@ def process_repositories(args, service):
 | 
			
		||||
                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):
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user