Last active
January 29, 2026 17:37
-
-
Save maxisandoval37/a9bbe29fd33321601fd64a74be0fb9a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| MSG_FILE="${1:-}" | |
| [[ -z "$MSG_FILE" || ! -f "$MSG_FILE" ]] && exit 0 | |
| if command -v commitg >/dev/null 2>&1; then | |
| commitg validate --repo "." --file "$MSG_FILE" | |
| exit 0 | |
| fi | |
| COMMITG_CSPROJ="../commitg-ia/commitg-ia.csproj" | |
| dotnet run --project "$COMMITG_CSPROJ" -- validate --repo "." --file "$MSG_FILE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal EnableExtensions EnableDelayedExpansion | |
| color 0A | |
| title Instalador-Hooks | |
| echo ===================================================================== | |
| echo Instalador de Hooks en Repo | |
| echo By: maxisandoval37 | |
| echo ===================================================================== | |
| echo. | |
| echo. | |
| echo _________-----_____ | |
| echo ____------ __ ----_ | |
| echo ___---- ___------ \ | |
| echo ----________ ---- \ | |
| echo -----__ ^| _____) | |
| echo __- / \ | |
| echo _______----- ___-- \ /)\ | |
| echo ------_______ ---____ \__/ / | |
| echo -----__ \ -- _ /\ | |
| echo --__--__ \_____/ \_/\ | |
| echo ---^| / ^| | |
| echo ^| ^|___________^| | |
| echo ^| ^| ((_(_)^| )_) | |
| echo ^| \_((_(_)^|/(_) | |
| echo \ ( | |
| echo \_____________) | |
| echo. | |
| echo. | |
| REM --- Validaciones--- | |
| if not exist ".git" ( | |
| echo ERROR: No se encontro carpeta .git. Ejecuta este script en la raiz de un repo git. | |
| echo. | |
| ) | |
| REM --- Asegurar carpeta hooks --- | |
| if not exist ".git\hooks" ( | |
| mkdir ".git\hooks" >nul 2>&1 | |
| ) | |
| REM --- Paths --- | |
| set "HOOK_PREP=.git\hooks\prepare-commit-msg" | |
| set "HOOK_COMMIT=.git\hooks\commit-msg" | |
| set "URL_PREP=https://gist.githubusercontent.com/maxisandoval37/a9bbe29fd33321601fd64a74be0fb9a4/raw/9f1e3d3661088df2ee55c69895f6ec4f9b806d39/prepare-commit-msg" | |
| set "URL_COMMIT=https://gist.githubusercontent.com/maxisandoval37/a9bbe29fd33321601fd64a74be0fb9a4/raw/9f1e3d3661088df2ee55c69895f6ec4f9b806d39/commit-msg" | |
| echo ============================================================ | |
| echo Descargar prepare-commit-msg | |
| echo ============================================================ | |
| echo. | |
| powershell -Command "& {Invoke-WebRequest -Uri '%URL_PREP%' -OutFile '%HOOK_PREP%'}" | |
| if errorlevel 1 ( | |
| echo ERROR: No se pudo descargar prepare-commit-msg | |
| echo URL: %URL_PREP% | |
| echo. | |
| ) | |
| echo OK: prepare-commit-msg descargado | |
| echo. | |
| echo ============================================================ | |
| echo Descargar commit-msg | |
| echo ============================================================ | |
| echo. | |
| powershell -Command "& {Invoke-WebRequest -Uri '%URL_COMMIT%' -OutFile '%HOOK_COMMIT%'}" | |
| if errorlevel 1 ( | |
| echo ERROR: No se pudo descargar commit-msg | |
| echo URL: %URL_COMMIT% | |
| echo. | |
| ) | |
| echo OK: commit-msg descargado | |
| echo. | |
| echo ============================================================ | |
| echo Configurar hooksPath | |
| echo ============================================================ | |
| echo. | |
| git config core.hooksPath .git/hooks | |
| if errorlevel 1 ( | |
| echo ERROR: No se pudo ejecutar git config core.hooksPath .git/hooks | |
| echo. | |
| ) | |
| echo OK: Hooks instalados en .git\hooks | |
| echo OK: core.hooksPath configurado a .git/hooks | |
| echo. | |
| echo Nota: estos hooks requieren Git Bash (bash). | |
| echo. | |
| echo ============================================================ | |
| echo. | |
| pause |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| MSG_FILE="${1:-}" | |
| [[ -z "$MSG_FILE" || ! -f "$MSG_FILE" ]] && exit 0 | |
| WI_ID="" | |
| if grep -Eq '#[0-9]+' "$MSG_FILE"; then | |
| WI_ID="$(grep -Eo '#[0-9]+' "$MSG_FILE" | head -n1 | tr -d '#')" | |
| elif grep -Eq 'WI:\s*[0-9]+' "$MSG_FILE"; then | |
| WI_ID="$(grep -Eo 'WI:\s*[0-9]+' "$MSG_FILE" | head -n1 | tr -dc '0-9')" | |
| fi | |
| [[ -z "$WI_ID" ]] && exit 0 | |
| # 1) Preferir el comando instalado (si existe) | |
| if command -v commitg >/dev/null 2>&1; then | |
| commitg generate --repo "." --staged --wi "$WI_ID" --out "$MSG_FILE" || exit 0 | |
| exit 0 | |
| fi | |
| # 2) Fallback: ejecutar el proyecto .NET directo | |
| COMMITG_CSPROJ="../commitg-ia/commitg-ia.csproj" | |
| dotnet run --project "$COMMITG_CSPROJ" -- generate --repo "." --staged --wi "$WI_ID" --out "$MSG_FILE" || exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment