aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/content/models
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2022-08-16 21:19:53 +0400
committerGravatar Hassan Abouelela <[email protected]>2022-08-16 21:19:53 +0400
commitf2374900c4c83097c105b56de02ea82d66bd9466 (patch)
treee886551b2dc3e92397160d5dd8886fb3a42d1909 /pydis_site/apps/content/models
parentMove GitHub strptime Format To Settings (diff)
Unify Tag Migrations & Add Commit Model
Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'pydis_site/apps/content/models')
-rw-r--r--pydis_site/apps/content/models/__init__.py4
-rw-r--r--pydis_site/apps/content/models/tag.py36
2 files changed, 38 insertions, 2 deletions
diff --git a/pydis_site/apps/content/models/__init__.py b/pydis_site/apps/content/models/__init__.py
index 2718ce94..60007e27 100644
--- a/pydis_site/apps/content/models/__init__.py
+++ b/pydis_site/apps/content/models/__init__.py
@@ -1,3 +1,3 @@
-from .tag import Tag
+from .tag import Commit, Tag
-__all__ = ["Tag"]
+__all__ = ["Commit", "Tag"]
diff --git a/pydis_site/apps/content/models/tag.py b/pydis_site/apps/content/models/tag.py
index 01264ff1..1c89fe1e 100644
--- a/pydis_site/apps/content/models/tag.py
+++ b/pydis_site/apps/content/models/tag.py
@@ -1,6 +1,36 @@
+import json
+
from django.db import models
+class Commit(models.Model):
+ """A git commit."""
+
+ URL_BASE = "https://github.com/python-discord/bot/commit/"
+
+ sha = models.CharField(
+ help_text="The SHA hash of this commit.",
+ primary_key=True,
+ max_length=40,
+ )
+ message = models.TextField(help_text="The commit message.")
+ date = models.DateTimeField(help_text="The date and time the commit was created.")
+ author = models.TextField(help_text="The person(s) who created the commit.")
+
+ @property
+ def url(self) -> str:
+ """The URL to the commit on GitHub."""
+ return self.URL_BASE + self.sha
+
+ @property
+ def format_users(self) -> str:
+ """Return a nice representation of the user(s)' name and email."""
+ authors = []
+ for author in json.loads(self.author):
+ authors.append(f"{author['name']} <{author['email']}>")
+ return ", ".join(authors)
+
+
class Tag(models.Model):
"""A tag from the python-discord server."""
@@ -10,6 +40,12 @@ class Tag(models.Model):
help_text="The date and time this data was last fetched.",
auto_now=True,
)
+ last_commit = models.OneToOneField(
+ Commit,
+ help_text="The commit this file was last touched in.",
+ null=True,
+ on_delete=models.CASCADE,
+ )
name = models.CharField(
help_text="The tag's name.",
primary_key=True,