Skip to content

sai dai

sai dai #32

Workflow file for this run

name: PR Analyzer
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- name: Checkout código
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.repository }}
- name: Configurar entorno
env:
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
run: echo "GOOGLE_API_KEY=${GOOGLE_API_KEY}" > .env
- name: Configurar Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Instalar dependencias
run: pip install rich python-dotenv google-generativeai
- name: Extraer cambios del PR con contexto
run: |
echo "📄 Extrayendo cambios del PR con contexto..."
# Crear rama temporal del PR
git fetch origin +refs/pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }}
# Archivo donde se guardará el diff contextual
> code_changes.txt
# Extraer nombres de archivos modificados
CHANGED_FILES=$(git diff --name-only origin/main...pr-${{ github.event.pull_request.number }})
# Si no hay archivos modificados, registrar aviso
if [ -z "$CHANGED_FILES" ]; then
echo "⚠️ No se detectaron archivos modificados." > code_changes.txt
else
for FILE in $CHANGED_FILES; do
echo "\n\n===============================" >> code_changes.txt
echo "📂 Archivo: $FILE" >> code_changes.txt
echo "===============================" >> code_changes.txt
# Extraer los cambios con 15 líneas de contexto
git diff -U15 origin/main...pr-${{ github.event.pull_request.number }} -- "$FILE" >> code_changes.txt
done
fi
head -n 40 code_changes.txt || true
- name: Obtener estructura del proyecto
run: |
echo "📁 Generando estructura del proyecto..."
tree -L 2 -I '.git|__pycache__|env|venv|node_modules' > estructura.txt || echo "Sin estructura generada"
- name: Ejecutar análisis con GoodDev
env:
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
run: python3 -m src.GoodDev | tee $GITHUB_WORKSPACE/pull_request.log
- name: Subir log como artifact
uses: actions/upload-artifact@v4
with:
name: pull_request_log
path: ${{ github.workspace }}/pull_request.log
- name: Comentar resultado en el PR
uses: marocchino/sticky-pull-request-comment@v2
with:
path: ${{ github.workspace }}/pull_request.log
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}