Skip to content

Feature: Récupération des détails d’un projet #22

Feature: Récupération des détails d’un projet

Feature: Récupération des détails d’un projet #22

Workflow file for this run

name: LLM Review & Email Notification
on:
pull_request:
types: [opened, synchronize]
branches: [develop]
permissions:
contents: write
pull-requests: write
issues: write
jobs:
review_and_notify:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get PR diff (src only)
id: diff
run: |
echo "🔍 Récupération du diff..."
git fetch origin develop || true
git diff origin/develop...HEAD -- 'src/**' '*.js' '*.ts' > diff.txt || true
if [ ! -s diff.txt ]; then
echo "diff=" >> $GITHUB_OUTPUT
else
echo "✅ Diff récupéré :"
head -n 10 diff.txt
# Encode le diff en Base64 pour éviter les erreurs JSON
DIFF_B64=$(base64 -w 0 diff.txt)
echo "diff_b64=$DIFF_B64" >> $GITHUB_OUTPUT
fi
- name: Call LLM for Code Review
id: llm
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
run: |
echo "🧠 Lecture du diff..."
if [ ! -f diff.txt ] || [ ! -s diff.txt ]; then
echo "⚠️ Aucun diff trouvé."
echo "LLM_RESPONSE=" >> $GITHUB_OUTPUT
exit 0
fi
CHUNK_SIZE=300
echo "" > llm_feedback.txt
split -l $CHUNK_SIZE diff.txt diff_chunk_
for file in diff_chunk_*
do
echo "🧠 Envoi du chunk $file à l'IA..."
# Échapper le diff en JSON
DIFF_JSON=$(jq -Rs . < "$file")
RESPONSE=$(curl -s "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GEMINI_API_KEY" \
-d @- <<EOF
{
"model": "gemini-2.0-flash",
"messages": [
{
"role": "user",
"content": "Tu es un relecteur de code expert. Analyse ce diff. Si le code est bon, fournis des pistes d'amélioration. Si le code contient des bugs, liste-les. Réponds en français.\n\n$DIFF_JSON"
}
]
}
EOF
)
ERROR=$(echo "$RESPONSE" | jq -r '.[0].error.message // empty')
if [ -n "$ERROR" ]; then
echo "⚠️ LLM error: $ERROR"
echo "LLM_RESPONSE=Erreur LLM : $ERROR" >> $GITHUB_OUTPUT
exit 0
fi
FEEDBACK=$(echo "$RESPONSE" | jq -r '.[0].message.content' 2>/dev/null || echo "")
echo -e "\n--- Chunk $file ---\n$FEEDBACK" >> llm_feedback.txt
sleep 5
done
FEEDBACK=$(cat llm_feedback.txt)
echo "LLM_RESPONSE<<EOF" >> $GITHUB_OUTPUT
echo "$FEEDBACK" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Comment on PR with LLM feedback
if: ${{ steps.llm.outputs.LLM_RESPONSE != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const feedback = process.env.FEEDBACK;
const prNumber = context.payload.pull_request.number;
const actor = context.actor;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `🤖 **Revue IA pour @${actor}**\n\n${feedback}`
});
env:
FEEDBACK: ${{ steps.llm.outputs.LLM_RESPONSE }}
- name: Send Email Notification
if: ${{ steps.llm.outputs.LLM_RESPONSE != '' }}
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.MAIL_USERNAME }}
password: ${{ secrets.MAIL_PASSWORD }}
subject: "Revue IA pour PR #${{ github.event.pull_request.number }} par @${{ github.actor }}"
to: ${{ secrets.TEAM_EMAIL_LIST }}
from: ${{ secrets.MAIL_USERNAME }}
body: |
Bonjour l'équipe 👋,
Une nouvelle revue IA vient d'être générée pour la Pull Request #${{ github.event.pull_request.number }} par @${{ github.actor }}.
Voici le retour de l'IA :
${{ steps.llm.outputs.LLM_RESPONSE }}