git documentation feature

This commit is contained in:
Joren de Graaf
2026-10-20 19:10:00 +02:00
parent 03d7afc6a1
commit a15c1f4c94
21 changed files with 1242 additions and 9 deletions
+44
View File
@@ -1,4 +1,5 @@
import uuid
from urllib.parse import urlsplit
from django.conf import settings
from django.core.validators import RegexValidator
from django.core.exceptions import ValidationError
@@ -39,6 +40,49 @@ class Project(models.Model):
class Meta:
constraints = [models.UniqueConstraint(fields=['owner', 'slug'], name='unique_owner_project_slug'), models.UniqueConstraint(fields=['owner', 'name'], name='unique_owner_project_name')]
def clean(self):
if self.git_repository_url:
try:
parsed = urlsplit(self.git_repository_url)
_ = parsed.port
valid = parsed.scheme == 'https' and bool(parsed.hostname)
except ValueError:
valid = False
parsed = None
if (not valid or parsed.username or parsed.password or parsed.query or parsed.fragment or
'\\' in self.git_repository_url or any(c.isspace() for c in self.git_repository_url)):
raise ValidationError({'git_repository_url': 'Use an HTTPS Git URL without credentials or query parameters.'})
class DocumentationSync(models.Model):
project = models.OneToOneField(Project, on_delete=models.CASCADE, related_name='documentation_sync')
branch = models.CharField(max_length=255, blank=True)
indexed_repository_url = models.URLField(blank=True)
indexed_commit = models.CharField(max_length=64, blank=True)
remote_head = models.CharField(max_length=64, blank=True)
commit_time = models.DateTimeField(null=True, blank=True)
last_success_at = models.DateTimeField(null=True, blank=True)
last_attempt_at = models.DateTimeField(null=True, blank=True)
last_error = models.CharField(max_length=300, blank=True)
sync_token = models.CharField(max_length=36, blank=True)
sync_started_at = models.DateTimeField(null=True, blank=True)
audit_state = models.JSONField(default=dict, blank=True)
class ProjectDocument(models.Model):
project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='documents')
path = models.CharField(max_length=500)
title = models.CharField(max_length=255)
headings = models.JSONField(default=list)
markdown = models.TextField()
content_hash = models.CharField(max_length=64)
source_commit = models.CharField(max_length=64)
class Meta:
ordering = ['path']
constraints = [models.UniqueConstraint(fields=['project', 'path'], name='unique_project_document_path')]
indexes = [models.Index(fields=['project', 'path'])]
class Membership(models.Model):
ROLE = [('editor', 'Editor'), ('viewer', 'Viewer')]