blob: 4d8bc552fe17b1054e15f0773227430b86971347 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import collections.abc
import json
from django.db import models
class Commit(models.Model):
"""A git commit from the Python Discord Bot project."""
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.")
authors = models.TextField(help_text=(
"The person(s) who created the commit. This is a serialized JSON object. "
"Refer to the GitHub documentation on the commit endpoint "
"(schema/commit.author & schema/commit.committer) for more info. "
"https://docs.github.com/en/rest/commits/commits#get-a-commit"
))
@property
def url(self) -> str:
"""The URL to the commit on GitHub."""
return self.URL_BASE + self.sha
def lines(self) -> collections.abc.Iterable[str]:
"""Return each line in the commit message."""
yield from self.message.split("\n")
def format_authors(self) -> collections.abc.Iterable[str]:
"""Return a nice representation of the author(s)' name and email."""
for author in json.loads(self.authors):
yield f"{author['name']} <{author['email']}>"
|