Добавить Cursor rules, init-cursor и скрипты настройки git remotes.
Канонический источник для клонирования в $HOME\CursorRules на новых ПК.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#Requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Создать репозиторий на home Gitea через API, если его ещё нет.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$RepoName,
|
||||
[string]$Owner = 'PapaTramp',
|
||||
[string]$ConfigPath = "$HOME\CursorRules\local\papatramp-gitea.conf",
|
||||
[string]$Description = ''
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
if (-not (Test-Path -LiteralPath $ConfigPath)) {
|
||||
throw "Config not found: $ConfigPath"
|
||||
}
|
||||
|
||||
$cfg = @{}
|
||||
Get-Content -LiteralPath $ConfigPath | ForEach-Object {
|
||||
if ($_ -match '^([^#=]+)=(.*)$') {
|
||||
$cfg[$Matches[1].Trim()] = $Matches[2].Trim()
|
||||
}
|
||||
}
|
||||
|
||||
$base = $cfg.GiteaApiUrl.TrimEnd('/')
|
||||
$pair = '{0}:{1}' -f $cfg.GiteaApiUser, $cfg.GiteaApiPassword
|
||||
$auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($pair))
|
||||
$headers = @{ Authorization = $auth; 'Content-Type' = 'application/json' }
|
||||
|
||||
$checkUrl = "$base/api/v1/repos/$Owner/$RepoName"
|
||||
try {
|
||||
$existing = Invoke-RestMethod -Method Get -Uri $checkUrl -Headers $headers -TimeoutSec 15
|
||||
Write-Host "[+] EXISTS $($existing.full_name)" -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
catch {
|
||||
if ($_.Exception.Response.StatusCode.value__ -ne 404) {
|
||||
throw "check failed: $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
$body = (@{
|
||||
name = $RepoName
|
||||
private = $true
|
||||
auto_init = $false
|
||||
description = $Description
|
||||
} | ConvertTo-Json)
|
||||
|
||||
foreach ($url in @("$base/api/v1/orgs/$Owner/repos", "$base/api/v1/user/repos")) {
|
||||
try {
|
||||
$created = Invoke-RestMethod -Method Post -Uri $url -Headers $headers -Body $body -TimeoutSec 30
|
||||
Write-Host "[+] CREATED $($created.full_name)" -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
catch {
|
||||
Write-Warning "create via $url : $($_.Exception.Message)"
|
||||
}
|
||||
}
|
||||
|
||||
throw 'failed to create repository on home Gitea'
|
||||
@@ -0,0 +1,97 @@
|
||||
#Requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Стандартные git remote: home, kalinamall, github.
|
||||
|
||||
.EXAMPLE
|
||||
cd C:\Users\papat\Projects\MyRepo
|
||||
& "$HOME\CursorRules\scripts\Set-GitRemotes.ps1"
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$Owner = 'PapaTramp',
|
||||
[string]$GithubOrg = 'PTah',
|
||||
[string]$Repo = '',
|
||||
[switch]$SkipKalinamall,
|
||||
[switch]$WhatIf
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Write-Step([string]$Message) { Write-Host "[*] $Message" -ForegroundColor Cyan }
|
||||
function Write-Ok([string]$Message) { Write-Host "[+] $Message" -ForegroundColor Green }
|
||||
|
||||
function Test-GitRepo {
|
||||
git rev-parse --is-inside-work-tree 2>$null | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw 'Run inside a git repository or pass -Repo.'
|
||||
}
|
||||
}
|
||||
|
||||
function Get-RepoName {
|
||||
param([string]$Name)
|
||||
if ($Name) { return $Name }
|
||||
return (Split-Path -Leaf (git rev-parse --show-toplevel))
|
||||
}
|
||||
|
||||
function Set-Remote {
|
||||
param(
|
||||
[string]$Name,
|
||||
[string]$Url
|
||||
)
|
||||
|
||||
$existing = git remote 2>$null
|
||||
$has = $existing -contains $Name
|
||||
|
||||
if ($WhatIf) {
|
||||
Write-Step "WhatIf: remote $Name -> $Url"
|
||||
return
|
||||
}
|
||||
|
||||
if ($has) {
|
||||
$current = (git remote get-url $Name 2>$null).Trim()
|
||||
if ($current -eq $Url) {
|
||||
Write-Ok "remote $Name OK"
|
||||
return
|
||||
}
|
||||
git remote set-url $Name $Url
|
||||
Write-Ok "remote $Name updated -> $Url"
|
||||
return
|
||||
}
|
||||
|
||||
$legacy = @{
|
||||
home = @('gitea', 'papatramp', 'origin-home')
|
||||
github = @('origin')
|
||||
kalinamall = @('gitea-kalinamall', 'kalina')
|
||||
}
|
||||
foreach ($old in $legacy[$Name]) {
|
||||
if ($existing -contains $old) {
|
||||
git remote rename $old $Name
|
||||
git remote set-url $Name $Url
|
||||
Write-Ok "remote $old renamed to $Name -> $Url"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
git remote add $Name $Url
|
||||
Write-Ok "remote $Name added -> $Url"
|
||||
}
|
||||
|
||||
Test-GitRepo
|
||||
$repoName = Get-RepoName -Name $Repo
|
||||
|
||||
$homeUrl = "ssh://git@git.papatramp.lan:2222/${Owner}/${repoName}.git"
|
||||
$kalinamallUrl = "ssh://git@git.kalinamall.lan:2222/${Owner}/${repoName}.git"
|
||||
$githubUrl = "git@github.com:${GithubOrg}/${repoName}.git"
|
||||
|
||||
Write-Step "Repo: $repoName"
|
||||
Set-Remote -Name 'home' -Url $homeUrl
|
||||
Set-Remote -Name 'github' -Url $githubUrl
|
||||
if (-not $SkipKalinamall) {
|
||||
Set-Remote -Name 'kalinamall' -Url $kalinamallUrl
|
||||
}
|
||||
|
||||
Write-Host ''
|
||||
Write-Host 'Remotes:' -ForegroundColor Magenta
|
||||
git remote -v
|
||||
Reference in New Issue
Block a user