[Python] Python bulk update repos [closed]

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    This code here should be able to bulk update multiple repos and create new branches and it should be able to create new Merge requests This code here should be able to bulk update multiple repos and create new branches and it should be able to create new Merge requests This code here should be able to bulk update multiple repos and create new branches and it should be able to create new Merge requests This code here should be able to bulk update multiple repos and create new branches and it should be able to create new Merge requests


    def run_command(command, repo_path):
    """Runs a shell command in the given repository."""
    try:
    result = subprocess.run(command, cwd=repo_path, shell=True, check=True, capture_output=True, text=True)
    return result.stdout.strip()
    except subprocess.CalledProcessError as e:
    print(f"Error in {repo_path}: {e.stderr.strip()}")
    return None

    def process_repo(repo):
    """Processes a single Git repository."""
    repo_path = os.path.join(PARENT_DIR, repo)

    os.path.isdir(os.path.join(repo_path, ".git")):
    print(f"Skipping {repo} (not a Git repo)")
    return
    print(f"\nProcessing repository: {repo}")


    run_command(f"git fetch {REMOTE}", repo_path)
    if run_command(f"git checkout {TARGET_BRANCH}", repo_path) is None:
    print(f"Skipping {repo} (no {TARGET_BRANCH} branch)")
    return
    run_command(f"git pull {REMOTE} {TARGET_BRANCH}", repo_path)
    run_command(f"git checkout -b {BRANCH_NAME}", repo_path)

    file_path = os.path.join(repo_path, "automation.txt")
    with open(file_path, "a") as f:
    f.write("Updated by script\n")

    run_command(f"git add automation.txt", repo_path)
    run_command(f'git commit -m "{COMMIT_MSG}"', repo_path)
    run_command(f"git push -u {REMOTE} {BRANCH_NAME}", repo_path)


    run_command(f'glab mr create --source-branch {BRANCH_NAME} --target-branch {TARGET_BRANCH} --title "Merge {BRANCH_NAME}" --description "Automated merge request"', repo_path)

    if __name__ == "__main__":

    for repo in os.listdir(PARENT_DIR):
    if os.path.isdir(os.path.join(PARENT_DIR, repo)):
    process_repo(repo)

    print("\n✅ Done!")

    '''

    This code here should be able to bulk update multiple repos and create new branches and it should be able to create new Merge requests
    This code here should be able to bulk update multiple repos and create new branches and it should be able to create new Merge requests

    This code here should be able to bulk update multiple repos and create new branches and it should be able to create new Merge requests
    This code here should be able to bulk update multiple repos and create new branches and it should be able to create new Merge requests

    Continue reading...

Compartilhe esta Página