✨ feat(ansible): Ajoute la mise à jour du journal client et permissions fichier ✨ feat(HomeController): Récupère et affiche le journal de bord client. 📦️ chore: Ajoute gemini-api-php/client et corrige des dépendances. 🐛 fix(docker): Supprime la configuration Xdebug obsolète. ```
125 lines
4.3 KiB
PHP
125 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
use Symfony\Component\Process\Process;
|
|
// Utilisation des namespaces que tu as fournis
|
|
use GeminiAPI\Client;
|
|
use GeminiAPI\Resources\Parts\TextPart;
|
|
|
|
#[AsCommand(
|
|
name: 'app:git-log-update',
|
|
description: 'Archive le dernier commit avec reformulation IA pour le client.',
|
|
)]
|
|
class GitSyncLogCommand extends Command
|
|
{
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
$filePath = 'var/update.json';
|
|
$projectDir = '/srv/app';
|
|
|
|
// 1. Récupération des infos Git
|
|
$gitCmd = sprintf(
|
|
'git config --global --add safe.directory %s && git log -1 --format="%%s|%%ci|%%h"',
|
|
$projectDir
|
|
);
|
|
|
|
$process = Process::fromShellCommandline($gitCmd);
|
|
$process->run();
|
|
|
|
if (!$process->isSuccessful()) {
|
|
$io->error("Erreur Git : " . $process->getErrorOutput());
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$outputGit = explode('|', trim($process->getOutput()));
|
|
$rawMessage = $outputGit[0] ?? '';
|
|
$commitDate = $outputGit[1] ?? date('Y-m-d H:i:s');
|
|
$commitHash = $outputGit[2] ?? 'unknown';
|
|
|
|
// 2. Détermination du TYPE (feature, fix, optimise, new)
|
|
$type = 'new';
|
|
$lowerMsg = strtolower($rawMessage);
|
|
|
|
if (preg_match('/(fix|bug|patch|correct)/', $lowerMsg)) {
|
|
$type = 'fix';
|
|
} elseif (preg_match('/(feat|add|create|nouveau|new)/', $lowerMsg)) {
|
|
$type = 'feature';
|
|
} elseif (preg_match('/(perf|opti|refactor|clean|speed)/', $lowerMsg)) {
|
|
$type = 'optimise';
|
|
}
|
|
|
|
// 3. Vérification anti-doublon (Basée sur le Hash)
|
|
$data = [];
|
|
if (file_exists($filePath)) {
|
|
$data = json_decode(file_get_contents($filePath), true) ?? [];
|
|
}
|
|
|
|
if (!empty($data) && $data[0]['hash'] === $commitHash) {
|
|
$io->info("Le commit [$commitHash] est déjà dans le journal client.");
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
// 4. Appel IA Gemini-3-Pro-Preview pour la reformulation
|
|
$friendlyMessage = $rawMessage;
|
|
try {
|
|
// Ta clé API
|
|
$client = new Client("AIzaSyDTPJERlUC47bcvhZU51Lwpqb1uxXS8SIg");
|
|
$model = 'gemini-3-pro-preview';
|
|
|
|
$prompt = "Tu es un expert en communication web pour Ludik Event. Ta mission est de transformer
|
|
un message de commit technique en une note de mise à jour élégante pour ton client.
|
|
|
|
MESSAGE TECHNIQUE : \"$rawMessage\"
|
|
|
|
DIRECTIVES :
|
|
1. Reformule pour un propriétaire de site non-technique.
|
|
2. Sois court, positif et rassurant.
|
|
3. Ne commence JAMAIS par 'Voici la phrase' ou 'Mise à jour'.
|
|
4. Donne uniquement le texte final prêt à être affiché.
|
|
|
|
RÉSULTAT ATTENDU :";
|
|
|
|
$response = $client->withV1BetaVersion()->generativeModel($model)->generateContent(
|
|
new TextPart($prompt)
|
|
);
|
|
|
|
// Adaptation selon la structure de retour du SDK
|
|
$aiText = $response->text();
|
|
if ($aiText) {
|
|
$friendlyMessage = trim($aiText);
|
|
}
|
|
} catch (\Exception $e) {
|
|
$io->warning("L'IA n'a pas pu traiter le message. Utilisation du texte brut.");
|
|
}
|
|
|
|
// 5. Création de l'entrée JSON
|
|
$newEntry = [
|
|
'type' => $type,
|
|
'message' => $friendlyMessage,
|
|
'date' => $commitDate,
|
|
'hash' => $commitHash
|
|
];
|
|
|
|
// 6. Sauvegarde et rotation (5 max)
|
|
array_unshift($data, $newEntry);
|
|
$data = array_slice($data, 0, 5);
|
|
|
|
if (!is_dir('var')) {
|
|
mkdir('var', 0777, true);
|
|
}
|
|
|
|
file_put_contents($filePath, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
|
|
|
$io->success("Journal client mis à jour avec succès (Type: $type).");
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|