<# .SYNOPSIS Create a new GitHub repository for a project that will be deployed to Coolify. .DESCRIPTION Calls the GitHub REST API with GITHUB_TOKEN to create a new repository under the authenticated user. After creation, prints the clone URL (HTTPS) and the SSH push URL. Idempotent in the sense that if the repo already exists it aborts with a clear message instead of failing. .PARAMETER Name Repository name (required). GitHub naming rules: lowercase, digits, '-' '_' '.'. .PARAMETER Description Short description shown on GitHub. .PARAMETER Private Switch. If set, creates a private repository. Default is public (Coolify public-app deploy does not need a deploy key). .PARAMETER Owner Optional. Organization or user to create the repo under. Defaults to the authenticated user (the owner of GITHUB_TOKEN). .EXAMPLE .\New-GitHubRepo.ps1 -Name "my-cool-app" -Description "Demo" -Private #> param( [Parameter(Mandatory = $true)] [ValidatePattern('^[A-Za-z0-9._-]+$')] [string]$Name, [string]$Description = "", [switch]$Private, [string]$Owner ) $ErrorActionPreference = "Stop" $here = Split-Path -Parent $MyInvocation.MyCommand.Path $ghApi = Join-Path $here "Invoke-GitHubApi.ps1" $me = & $ghApi -Path "/user" -ErrorAction Stop $effectiveOwner = if ($Owner) { $Owner } else { $me.login } Write-Host "Authenticated GitHub user: $($me.login)" -ForegroundColor Cyan $exists = $null try { $exists = & $ghApi -Path "/repos/$effectiveOwner/$Name" -ErrorAction Stop } catch { $exists = $null } if ($exists) { Write-Host "Repository already exists: https://github.com/$effectiveOwner/$Name" -ForegroundColor Yellow Write-Host "clone_url: $($exists.clone_url)" return $exists } $body = [ordered]@{ name = $Name description = $Description private = [bool]$Private auto_init = $true has_issues = $true has_wiki = $false } | ConvertTo-Json -Compress $endpoint = if ($Owner) { "/orgs/$Owner/repos" } else { "/user/repos" } Write-Host "Creating repository at: $endpoint" -ForegroundColor Cyan $created = & $ghApi -Method POST -Path $endpoint -BodyJson $body -ErrorAction Stop [PSCustomObject]@{ full_name = $created.full_name html_url = $created.html_url clone_url = $created.clone_url ssh_url = $created.ssh_url private = $created.private default_branch = $created.default_branch } | Format-List $created