def setup_git_repository()

in src/cli/commands/setup_cicd.py [0:0]


def setup_git_repository(config: ProjectConfig) -> str:
    """Set up Git repository and remote.

    Args:
        config: Project configuration containing repository details

    Returns:
        str: GitHub username of the authenticated user
    """
    console.print("\nšŸ”§ Setting up Git repository...")

    # Initialize git if not already initialized
    if not (Path.cwd() / ".git").exists():
        run_command(["git", "init", "-b", "main"])
        console.print("āœ… Git repository initialized")

    # Get current GitHub username for the remote URL
    result = run_command(["gh", "api", "user", "--jq", ".login"], capture_output=True)
    github_username = result.stdout.strip()

    # Add remote if it doesn't exist
    try:
        run_command(
            ["git", "remote", "get-url", "origin"], capture_output=True, check=True
        )
        console.print("āœ… Git remote already configured")
    except subprocess.CalledProcessError:
        remote_url = (
            f"https://github.com/{github_username}/{config.repository_name}.git"
        )
        run_command(["git", "remote", "add", "origin", remote_url])
        console.print(f"āœ… Added git remote: {remote_url}")

    console.print(
        "\nšŸ’” Tip: Don't forget to commit and push your changes to the repository!"
    )
    return github_username