|
4ce269c…
|
ragelink
|
1 |
from pathlib import Path |
|
4ce269c…
|
ragelink
|
2 |
|
|
4ce269c…
|
ragelink
|
3 |
from django.db import models |
|
4ce269c…
|
ragelink
|
4 |
|
|
4ce269c…
|
ragelink
|
5 |
from core.models import ActiveManager, Tracking |
|
4ce269c…
|
ragelink
|
6 |
|
|
4ce269c…
|
ragelink
|
7 |
|
|
4ce269c…
|
ragelink
|
8 |
class FossilRepository(Tracking): |
|
4ce269c…
|
ragelink
|
9 |
"""Links a Project to its on-disk .fossil SQLite file.""" |
|
4ce269c…
|
ragelink
|
10 |
|
|
4ce269c…
|
ragelink
|
11 |
project = models.OneToOneField("projects.Project", on_delete=models.CASCADE, related_name="fossil_repo") |
|
4ce269c…
|
ragelink
|
12 |
filename = models.CharField(max_length=255, unique=True, help_text="Filename relative to FOSSIL_DATA_DIR") |
|
4ce269c…
|
ragelink
|
13 |
file_size_bytes = models.BigIntegerField(default=0) |
|
4ce269c…
|
ragelink
|
14 |
fossil_project_code = models.CharField(max_length=40, blank=True, default="") |
|
4ce269c…
|
ragelink
|
15 |
last_checkin_at = models.DateTimeField(null=True, blank=True) |
|
4ce269c…
|
ragelink
|
16 |
checkin_count = models.PositiveIntegerField(default=0) |
|
4ce269c…
|
ragelink
|
17 |
|
|
4ce269c…
|
ragelink
|
18 |
# Remote sync |
|
4ce269c…
|
ragelink
|
19 |
remote_url = models.URLField(blank=True, default="", help_text="Upstream remote URL for sync") |
|
4ce269c…
|
ragelink
|
20 |
last_sync_at = models.DateTimeField(null=True, blank=True) |
|
4ce269c…
|
ragelink
|
21 |
upstream_artifacts_available = models.PositiveIntegerField(default=0, help_text="New artifacts available from upstream") |
|
4ce269c…
|
ragelink
|
22 |
|
|
4ce269c…
|
ragelink
|
23 |
# S3 tracking |
|
4ce269c…
|
ragelink
|
24 |
s3_key = models.CharField(max_length=500, blank=True, default="") |
|
4ce269c…
|
ragelink
|
25 |
s3_last_replicated_at = models.DateTimeField(null=True, blank=True) |
|
4ce269c…
|
ragelink
|
26 |
|
|
4ce269c…
|
ragelink
|
27 |
objects = ActiveManager() |
|
4ce269c…
|
ragelink
|
28 |
all_objects = models.Manager() |
|
4ce269c…
|
ragelink
|
29 |
|
|
4ce269c…
|
ragelink
|
30 |
class Meta: |
|
4ce269c…
|
ragelink
|
31 |
ordering = ["filename"] |
|
4ce269c…
|
ragelink
|
32 |
verbose_name = "Fossil Repository" |
|
4ce269c…
|
ragelink
|
33 |
verbose_name_plural = "Fossil Repositories" |
|
4ce269c…
|
ragelink
|
34 |
|
|
4ce269c…
|
ragelink
|
35 |
def __str__(self): |
|
4ce269c…
|
ragelink
|
36 |
return self.filename |
|
4ce269c…
|
ragelink
|
37 |
|
|
4ce269c…
|
ragelink
|
38 |
@property |
|
4ce269c…
|
ragelink
|
39 |
def full_path(self) -> Path: |
|
4ce269c…
|
ragelink
|
40 |
from constance import config |
|
4ce269c…
|
ragelink
|
41 |
|
|
4ce269c…
|
ragelink
|
42 |
return Path(config.FOSSIL_DATA_DIR) / self.filename |
|
4ce269c…
|
ragelink
|
43 |
|
|
4ce269c…
|
ragelink
|
44 |
@property |
|
4ce269c…
|
ragelink
|
45 |
def exists_on_disk(self) -> bool: |
|
4ce269c…
|
ragelink
|
46 |
return self.full_path.exists() |
|
4ce269c…
|
ragelink
|
47 |
|
|
4ce269c…
|
ragelink
|
48 |
|
|
4ce269c…
|
ragelink
|
49 |
class FossilSnapshot(Tracking): |
|
4ce269c…
|
ragelink
|
50 |
"""Binary snapshot of a .fossil file stored via Django's file storage.""" |
|
4ce269c…
|
ragelink
|
51 |
|
|
4ce269c…
|
ragelink
|
52 |
repository = models.ForeignKey(FossilRepository, on_delete=models.CASCADE, related_name="snapshots") |
|
4ce269c…
|
ragelink
|
53 |
file = models.FileField(upload_to="fossil_snapshots/%Y/%m/") |
|
4ce269c…
|
ragelink
|
54 |
file_size_bytes = models.BigIntegerField(default=0) |
|
4ce269c…
|
ragelink
|
55 |
fossil_hash = models.CharField(max_length=64, blank=True, default="", help_text="SHA-256 of the .fossil file") |
|
4ce269c…
|
ragelink
|
56 |
note = models.CharField(max_length=200, blank=True, default="") |
|
4ce269c…
|
ragelink
|
57 |
|
|
4ce269c…
|
ragelink
|
58 |
objects = ActiveManager() |
|
4ce269c…
|
ragelink
|
59 |
all_objects = models.Manager() |
|
4ce269c…
|
ragelink
|
60 |
|
|
4ce269c…
|
ragelink
|
61 |
class Meta: |
|
4ce269c…
|
ragelink
|
62 |
ordering = ["-created_at"] |
|
4ce269c…
|
ragelink
|
63 |
get_latest_by = "created_at" |
|
4ce269c…
|
ragelink
|
64 |
|
|
4ce269c…
|
ragelink
|
65 |
def __str__(self): |
|
4ce269c…
|
ragelink
|
66 |
return f"{self.repository.filename} @ {self.created_at:%Y-%m-%d %H:%M}" if self.created_at else self.repository.filename |
|
2eca4eb…
|
ragelink
|
67 |
|
|
2eca4eb…
|
ragelink
|
68 |
|
|
0da8377…
|
ragelink
|
69 |
# Import related models so they're discoverable by Django |
|
c588255…
|
ragelink
|
70 |
from fossil.agent_claims import TicketClaim # noqa: E402, F401 |
|
c588255…
|
ragelink
|
71 |
from fossil.api_tokens import APIToken # noqa: E402, F401 |
|
c588255…
|
ragelink
|
72 |
from fossil.branch_protection import BranchProtection # noqa: E402, F401 |
|
46f6d5e…
|
ragelink
|
73 |
from fossil.chat import ChatMessage # noqa: E402, F401 |
|
c588255…
|
ragelink
|
74 |
from fossil.ci import StatusCheck # noqa: E402, F401 |
|
c588255…
|
ragelink
|
75 |
from fossil.code_reviews import CodeReview, ReviewComment # noqa: E402, F401 |
|
c588255…
|
ragelink
|
76 |
from fossil.forum import ForumPost # noqa: E402, F401 |
|
c588255…
|
ragelink
|
77 |
from fossil.notifications import Notification, NotificationPreference, ProjectWatch # noqa: E402, F401 |
|
c588255…
|
ragelink
|
78 |
from fossil.releases import Release, ReleaseAsset # noqa: E402, F401 |
|
2eca4eb…
|
ragelink
|
79 |
from fossil.sync_models import GitMirror, SSHKey, SyncLog # noqa: E402, F401 |
|
c588255…
|
ragelink
|
80 |
from fossil.ticket_fields import TicketFieldDefinition # noqa: E402, F401 |
|
c588255…
|
ragelink
|
81 |
from fossil.ticket_reports import TicketReport # noqa: E402, F401 |
|
c588255…
|
ragelink
|
82 |
from fossil.user_keys import UserSSHKey # noqa: E402, F401 |
|
c588255…
|
ragelink
|
83 |
from fossil.webhooks import Webhook, WebhookDelivery # noqa: E402, F401 |
|
c588255…
|
ragelink
|
84 |
from fossil.workspaces import AgentWorkspace # noqa: E402, F401 |