NubeColectiva

Commits con IA (AI Commits)

Mar 30th, 2026 (edited)
353
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.93 KB | Source Code | 0 0
  1. function git-auto {
  2.     chcp 65001 > $null
  3.    
  4.     # Forzamos a la consola a usar UTF-8 para que las tildes se vean bien
  5.     $OutputEncoding = [System.Text.Encoding]::UTF8
  6.     [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  7.     [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  8.  
  9.     Write-Host "1. Stageando..." -ForegroundColor Gray
  10.     git add .
  11.    
  12.     $diff = git diff --cached --stat
  13.     if (-not $diff) {
  14.         Write-Host "Error: No hay cambios." -ForegroundColor Red
  15.         return
  16.     }
  17.  
  18.     Write-Host "2. Ollama: Analizando..." -ForegroundColor Gray
  19.    
  20.     $payload = @{
  21.         model = "llama3.2:3b"
  22.         prompt = "Analiza este DIFF de Git y genera un mensaje de commit muy breve (max 6 palabras) en español. Solo responde con el mensaje. DIFF: $diff"
  23.         stream = $false
  24.         options = @{ num_predict = 30; temperature = 0.1 }
  25.     } | ConvertTo-Json
  26.  
  27.     try {
  28.         $r = Invoke-RestMethod -Method Post -Uri "http://localhost:11434/api/generate" -Body $payload -ContentType "application/json; charset=utf-8"
  29.        
  30.         # Convertimos la respuesta de bytes crudos a UTF8 puro para evitar el ó
  31.         $bytes = [System.Text.Encoding]::GetEncoding("Latin1").GetBytes($r.response)
  32.         $m = [System.Text.Encoding]::UTF8.GetString($bytes).Trim().Trim(@([char]34))
  33.        
  34.         Write-Host " -> Commit: $m" -ForegroundColor Cyan
  35.        
  36.         # FIX: Forzamos a Git a entender que el mensaje lleva tildes en UTF-8
  37.         git -c "i18n.commitEncoding=utf-8" commit -m "$m"
  38.        
  39.         if ($LASTEXITCODE -eq 0) {
  40.             Write-Host "3. Enviando..." -ForegroundColor Magenta
  41.             git push
  42.             Start-Sleep -s 3
  43.             Write-Host "4. Hecho. Revisa tu repositorio." -FtuoregroundColor Green
  44.         }
  45.     }
  46.     catch {
  47.         Write-Host "Error: Ollama no responde." -ForegroundColor Red
  48.     }
  49. }
  50.  
  51. Set-Alias gup git-auto
Advertisement
Comments
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment