Cette mise a jour complete ameliore significativement la qualite et la maintenabilite du projet. 1. Extension de la couverture de tests Couverture globale passee de 8% a 16% (+100%) - Ajout de 25 nouveaux tests (total: 67 tests, 100% passent) - Nouveaux fichiers de tests: * tests/unit/test_gitea.py (17 tests) * tests/unit/test_fiches_tickets.py (8 tests) Etat de la couverture par module: - utils/gitea.py: 100% - utils/widgets.py: 100% - utils/logger.py: 94% - app/fiches/utils/tickets/core.py: 77% - utils/graph_utils.py: 59% 2. Documentation d'architecture complete Creation de 3 nouveaux documents (30 Ko total): - docs/ARCHITECTURE.md (15 Ko) * Architecture complete du projet * Flux de donnees detailles * Indices de vulnerabilite (IHH, ISG, ICS, IVC) * Structure du graphe NetworkX - docs/MODULES.md (15 Ko) * Guide des 11 modules principaux * Exemples de code (15+ snippets) * Bonnes pratiques * Guide de depannage - docs/README.md (4 Ko) * Index de toute la documentation Contenu documente: - 5 modules applicatifs - 6 modules utilitaires - 4 indices de vulnerabilite avec formules et seuils - Conventions de code 3. Reorganisation de la documentation Structure finale optimisee: - Racine: README.md (mis a jour) + Instructions.md - docs/: 11 documents organises par categorie Fichiers deplaces vers docs/: - README_connexion.md -> docs/CONNEXION.md - GUIDE_LOGS.md -> docs/ - GUIDE_RUFF.md -> docs/ - RAPPORT_RUFF.md -> docs/ - RAPPORT_CORRECTIONS_AUTO.md -> docs/ - REFACTORING_REPORT.md -> docs/ - VERIFICATION_LOGS.md -> docs/ - TODO_IA_BATCH.md -> docs/ 4. Ajout de docstrings 52 fonctions documentees en style Google (100%) Documentation en francais avec Args, Returns, Raises 5. Corrections automatiques Ruff Application de 347 corrections automatiques: - Formatage du code (line-length: 120) - Organisation des imports - Simplifications syntaxiques - Suppressions de code mort - Ameliorations de performance 6. Configuration qualite du code Nouveaux fichiers: - pyproject.toml: configuration Ruff complete - .vscode/settings.json: integration Ruff avec formatOnSave - GUIDE_RUFF.md: documentation du linter - GUIDE_LOGS.md: documentation du logging - .gitignore: ajout htmlcov/ pour rapports de couverture Etat final du projet: - Linter: Ruff configure (15 regles actives) - Tests: 67 tests (100% passent) - Couverture de code: 16% - Docstrings: 52/52 (100%) - Documentation: 11 fichiers organises Impact: - Tests plus robustes et maintenables - Documentation technique complete - Meilleure organisation des fichiers - Workflow optimise avec Ruff - Code pret pour integration continue References: - Architecture: docs/ARCHITECTURE.md - Guide modules: docs/MODULES.md - Tests: tests/unit/ - Configuration: pyproject.toml Co-Authored-By: Claude <noreply@anthropic.com>
158 lines
5.9 KiB
Python
158 lines
5.9 KiB
Python
# display.py
|
|
|
|
import html
|
|
import re
|
|
from collections import defaultdict
|
|
|
|
import streamlit as st
|
|
from dateutil import parser
|
|
|
|
from utils.logger import setup_logger
|
|
from utils.translations import _
|
|
|
|
logger = setup_logger(__name__)
|
|
|
|
|
|
def extraire_statut_par_label(ticket):
|
|
"""Extrait le statut d'un ticket depuis ses labels Gitea.
|
|
|
|
Recherche parmi les labels du ticket le premier correspondant a un statut connu
|
|
(Backlog, En attente, En cours, Termine, Rejete).
|
|
|
|
Args:
|
|
ticket: Dictionnaire representant un ticket Gitea avec cle 'labels'.
|
|
|
|
Returns:
|
|
str: Statut du ticket ou "Autres" si aucun statut reconnu.
|
|
"""
|
|
labels = [label.get('name', '') for label in ticket.get('labels', [])]
|
|
for statut in ["Backlog",
|
|
str(_("pages.fiches.tickets.status.awaiting")),
|
|
str(_("pages.fiches.tickets.status.in_progress")),
|
|
str(_("pages.fiches.tickets.status.completed")),
|
|
str(_("pages.fiches.tickets.status.rejected"))]:
|
|
if statut in labels:
|
|
return statut
|
|
return str(_("pages.fiches.tickets.status.others"))
|
|
|
|
|
|
def afficher_tickets_par_fiche(tickets):
|
|
"""Affiche les tickets associes a une fiche, groupes par statut.
|
|
|
|
Organise les tickets dans des expanders par statut (En attente, En cours, etc.)
|
|
et affiche un compteur de tickets en backlog si present.
|
|
|
|
Args:
|
|
tickets: Liste de tickets Gitea (dictionnaires).
|
|
"""
|
|
if not tickets:
|
|
st.info(str(_("pages.fiches.tickets.no_linked_tickets")))
|
|
return
|
|
|
|
st.markdown(str(_("pages.fiches.tickets.associated_tickets")))
|
|
tickets_groupes = defaultdict(list)
|
|
for ticket in tickets:
|
|
statut = extraire_statut_par_label(ticket)
|
|
tickets_groupes[statut].append(ticket)
|
|
|
|
nb_backlogs = len(tickets_groupes["Backlog"])
|
|
if nb_backlogs:
|
|
st.info(f"⤇ {nb_backlogs} {str(_('pages.fiches.tickets.moderation_notice'))}")
|
|
|
|
ordre_statuts = [
|
|
str(_("pages.fiches.tickets.status.awaiting")),
|
|
str(_("pages.fiches.tickets.status.in_progress")),
|
|
str(_("pages.fiches.tickets.status.completed")),
|
|
str(_("pages.fiches.tickets.status.rejected")),
|
|
str(_("pages.fiches.tickets.status.others"))
|
|
]
|
|
for statut in ordre_statuts:
|
|
if tickets_groupes[statut]:
|
|
with st.expander(f"{statut} ({len(tickets_groupes[statut])})", expanded=(statut == "En cours")):
|
|
for ticket in tickets_groupes[statut]:
|
|
afficher_carte_ticket(ticket)
|
|
|
|
|
|
def recuperer_commentaires_ticket(issue_index):
|
|
"""Recupere tous les commentaires d'un ticket Gitea.
|
|
|
|
Args:
|
|
issue_index: Numero d'index du ticket dans Gitea.
|
|
|
|
Returns:
|
|
list[dict]: Liste des commentaires (format JSON Gitea), liste vide si erreur.
|
|
"""
|
|
import requests
|
|
|
|
from config import DEPOT_FICHES, GITEA_TOKEN, GITEA_URL, ORGANISATION
|
|
|
|
headers = {"Authorization": f"token {GITEA_TOKEN}"}
|
|
url = f"{GITEA_URL}/repos/{ORGANISATION}/{DEPOT_FICHES}/issues/{issue_index}/comments"
|
|
try:
|
|
response = requests.get(url, headers=headers, timeout=10)
|
|
response.raise_for_status()
|
|
return response.json()
|
|
except Exception as e:
|
|
st.error(f"{str(_('pages.fiches.tickets.comment_error'))} {e}")
|
|
return []
|
|
|
|
|
|
def afficher_carte_ticket(ticket):
|
|
"""Affiche une carte Streamlit detaillee pour un ticket Gitea.
|
|
|
|
Affiche le titre, auteur, dates, labels, corps, et commentaires du ticket
|
|
dans un format visuellement organise.
|
|
|
|
Args:
|
|
ticket: Dictionnaire representant un ticket Gitea complet.
|
|
"""
|
|
titre = ticket.get("title", str(_("pages.fiches.tickets.no_title")))
|
|
url = ticket.get("html_url", "")
|
|
user = ticket.get("user", {}).get("login", str(_("pages.fiches.tickets.unknown")))
|
|
created = ticket.get("created_at", "")
|
|
updated = ticket.get("updated_at", "")
|
|
body = ticket.get("body", "")
|
|
labels = [l["name"] for l in ticket.get("labels", []) if "name" in l]
|
|
|
|
sujet = ""
|
|
match = re.search(r"## Sujet de la proposition\s+(.+?)(\n|$)", body, re.DOTALL)
|
|
if match:
|
|
sujet = match.group(1).strip()
|
|
|
|
def format_date(iso):
|
|
try:
|
|
return parser.isoparse(iso).strftime("%d/%m/%Y")
|
|
except (ValueError, TypeError) as e:
|
|
logger.warning(f"Format de date invalide: {iso} - {e}")
|
|
return "?"
|
|
|
|
date_created_str = format_date(created)
|
|
maj_info = f"({str(_('pages.fiches.tickets.updated'))} {format_date(updated)})" if updated and updated != created else ""
|
|
|
|
commentaires = recuperer_commentaires_ticket(ticket.get("number"))
|
|
commentaires_html = ""
|
|
for commentaire in commentaires:
|
|
auteur = html.escape(commentaire.get('user', {}).get('login', str(_("pages.fiches.tickets.unknown"))))
|
|
contenu = html.escape(commentaire.get('body', ''))
|
|
date = format_date(commentaire.get('created_at', ''))
|
|
commentaires_html += f"""
|
|
<div class=\"conteneur_commentaire\">
|
|
<p class=\"commentaire_auteur\"><strong>{auteur}</strong> <small>({date})</small></p>
|
|
<p class=\"commentaire_contenu\">{contenu}</p>
|
|
</div>
|
|
"""
|
|
|
|
with st.container():
|
|
st.markdown(f"""
|
|
<div class=\"conteneur_ticket\">
|
|
<h4><a href='{url}' target='_blank'>{titre}</a></h4>
|
|
<p>{str(_("pages.fiches.tickets.opened_by"))} <strong>{html.escape(user)}</strong> {str(_("pages.fiches.tickets.on_date"))} {date_created_str} {maj_info}</p>
|
|
<p>{str(_("pages.fiches.tickets.subject_label"))} : <strong>{html.escape(sujet)}</strong></p>
|
|
<p>Labels : {' • '.join(labels) if labels else str(_("pages.fiches.tickets.no_labels"))}</p>
|
|
</div>
|
|
""", unsafe_allow_html=True)
|
|
st.markdown(body, unsafe_allow_html=False)
|
|
st.markdown("---")
|
|
st.markdown(str(_("pages.fiches.tickets.comments")))
|
|
st.markdown(commentaires_html or str(_("pages.fiches.tickets.no_comments")), unsafe_allow_html=True)
|