Skip to content

feat: Implement project filtering by course name #27

feat: Implement project filtering by course name

feat: Implement project filtering by course name #27

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
DIFF_B64=$(base64 -w 0 diff.txt)
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 encodé en Base64. Décodes-le d'abord côté IA et ensuite, 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_B64"
}
]
}
EOF
)
FEEDBACK=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // ""')
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 }}