Skip to content

Instantly share code, notes, and snippets.

@maxisandoval37
Last active March 9, 2026 18:43
Show Gist options
  • Select an option

  • Save maxisandoval37/a9bbe29fd33321601fd64a74be0fb9a4 to your computer and use it in GitHub Desktop.

Select an option

Save maxisandoval37/a9bbe29fd33321601fd64a74be0fb9a4 to your computer and use it in GitHub Desktop.
#!/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"
@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
#!/usr/bin/env bash
set -euo pipefail
MSG_FILE="${1:-}"
[[ -z "$MSG_FILE" || ! -f "$MSG_FILE" ]] && exit 0
extract_wi() {
local file="$1"
if grep -Eq '#[0-9]+' "$file"; then
grep -Eo '#[0-9]+' "$file" | head -n1 | tr -d '#'
return 0
fi
if grep -Eqi 'WI:\s*[0-9]+' "$file"; then
grep -Eoi 'WI:\s*[0-9]+' "$file" | head -n1 | tr -dc '0-9'
return 0
fi
if grep -Eqi '^(Closes|Fixes|Resolves)\s+#[0-9]+' "$file"; then
grep -Eoi '^(Closes|Fixes|Resolves)\s+#[0-9]+' "$file" | head -n1 | grep -Eo '[0-9]+'
return 0
fi
return 1
}
WI_ID="$(extract_wi "$MSG_FILE" || true)"
[[ -z "$WI_ID" ]] && exit 0
# 1) Preferir el comando instalado
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