#!/usr/bin/env -S uv run --quiet --script # /// script # requires-python = ">=3.12" # dependencies = ["typer",'httpx'] # /// import subprocess import httpx import typer from pathlib import Path app = typer.Typer() DEFAULT_REPO = Path.cwd().name @app.command() def create( name: str = typer.Option(DEFAULT_REPO, help="Name of the repo", prompt=True), description: str = typer.Option( ..., "--description", "-d", help="Description for the repo", prompt=True ), remote: str = typer.Option("https://git.wayl.one", help="Base remote URL"), org: str = typer.Option("waylon", help="Organization or username"), branch: str = typer.Option("main", help="Branch to push"), dry_run: bool = typer.Option(False, help="Dry run"), ): typer.echo(f"Creating repo {name} on Forgejo...") cmd = ["tea", "repo", "create", "--name", name, "--description", description] if dry_run: typer.echo(" ".join(cmd)) else: subprocess.run( cmd, check=True, ) remote_url = f"{remote}/{org}/{name}.git" typer.echo(f"Adding remote: {remote_url}") if not Path(".gitignore").exists(): cmd = [ "curl", "-L", "https://www.gitignore.io/api/vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode", ">", ".gitignore", ] typer.echo("Creating .gitignore") if dry_run: typer.echo(" ".join(cmd)) else: gitignore = httpx.get("https://www.gitignore.io/api/vim,node,data,emacs,python,pycharm,executable,sublimetext,visualstudio,visualstudiocode") Path(".gitignore").write_text(gitignore.text) if not Path("README.md").exists(): readme = f"""# {name} {description} """ typer.echo("Creating README.md") if dry_run: typer.echo(readme) else: Path("README.md").write_text(readme) if not Path(".git").exists(): cmd = ["git", "init"] if dry_run: typer.echo(" ".join(cmd)) else: subprocess.run(cmd, check=True) cmd = ["git", "add", "."] if dry_run: typer.echo(" ".join(cmd)) else: subprocess.run(cmd, check=True) typer.echo("Added files") cmd = ["git", "commit", "-m", f"Initial Commit for {name}\n\n{description}"] if dry_run: typer.echo(" ".join(cmd)) else: subprocess.run(cmd, check=True) typer.echo("Created .git") cmd = ["git", "remote", "add", "origin", remote_url] typer.echo("Adding remote") if dry_run: typer.echo(" ".join(cmd)) else: subprocess.run(cmd, check=True) typer.echo(f"Pushing branch {branch} to origin...") cmd = ["git", "push", "-u", "origin", branch] if dry_run: cmd = ["git", "push", "-u", "origin", branch] typer.echo(" ".join(cmd)) else: subprocess.run(cmd, check=True) typer.echo("✅ Done!") if __name__ == "__main__": app()