in src/cli/utils/cicd.py [0:0]
def handle_github_authentication() -> None:
"""Handle GitHub CLI authentication interactively."""
console.print("\nš GitHub Authentication Required", style="bold yellow")
console.print("You need to authenticate with GitHub CLI to continue.")
console.print("Choose an authentication method:")
console.print("1. Login with browser")
console.print("2. Login with token")
choice = click.prompt(
"Select authentication method", type=click.Choice(["1", "2"]), default="1"
)
try:
if choice == "1":
# Browser-based authentication
run_command(["gh", "auth", "login", "--web"])
else:
# Token-based authentication
token = click.prompt(
"Enter your GitHub Personal Access Token", hide_input=True
)
# Use a subprocess with pipe to avoid showing the token in process list
process = subprocess.Popen(
["gh", "auth", "login", "--with-token"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
stdout, stderr = process.communicate(input=token + "\n")
if process.returncode != 0:
console.print(f"ā Authentication failed: {stderr}", style="bold red")
raise subprocess.CalledProcessError(
process.returncode, ["gh", "auth", "login"], stdout, stderr
)
console.print("ā
Successfully authenticated with GitHub", style="green")
except subprocess.CalledProcessError as e:
console.print(f"ā Authentication failed: {e}", style="bold red")
raise click.Abort() from e