Skip to content

Commit f8f33f9

Browse files
committed
feat: add to_v3_profile_dict to CommitAuthor model
1 parent fd4ee81 commit f8f33f9

2 files changed

Lines changed: 21 additions & 28 deletions

File tree

libraries/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ def display_name(self):
9999
def __str__(self):
100100
return self.name
101101

102+
def to_v3_profile_dict(self, role):
103+
return {
104+
"name": self.display_name or self.name,
105+
"profile_url": self.github_profile_url,
106+
"role": role,
107+
"avatar_url": self.avatar_url or "",
108+
"badge_url": None,
109+
}
110+
102111
@transaction.atomic
103112
def merge_author(self, other: Self):
104113
"""Update references to `other` to point to `self`.

libraries/views.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,6 @@
5353
# ── V3 context helpers ─────────────────────────────────────────────────────
5454

5555

56-
def _format_commit_authors_for_v3(authors, role):
57-
"""Convert CommitAuthor objects to the dict format expected by _user_profile.html."""
58-
result = []
59-
for author in authors:
60-
result.append(
61-
{
62-
"name": getattr(author, "display_name", None)
63-
or getattr(author, "name", str(author)),
64-
"profile_url": getattr(author, "github_profile_url", None),
65-
"role": role,
66-
"avatar_url": getattr(author, "avatar_url", "") or "",
67-
"badge_url": None,
68-
}
69-
)
70-
return result
71-
72-
7356
def _build_quick_start_links(documentation_url, github_url, github_issues_url):
7457
"""Build the quick-start links list for the V3 library hero card."""
7558
links = []
@@ -558,22 +541,23 @@ def get_v3_context_data(self, base_context=None, **kwargs):
558541
u.to_v3_profile_dict("Maintainer")
559542
for u in base_context.get("maintainers", [])
560543
]
561-
+ _format_commit_authors_for_v3(
562-
list(base_context.get("top_contributors_release_new", [])),
563-
"New Contributor",
564-
)
565-
+ _format_commit_authors_for_v3(
566-
list(base_context.get("top_contributors_release_old", [])),
567-
"Contributor",
568-
)
544+
+ [
545+
a.to_v3_profile_dict("New Contributor")
546+
for a in base_context.get("top_contributors_release_new", [])
547+
]
548+
+ [
549+
a.to_v3_profile_dict("Contributor")
550+
for a in base_context.get("top_contributors_release_old", [])
551+
]
569552
)
570553
context["this_release_contributors"] = (
571554
this_release or SharedResources.library_release_contributors
572555
)
573556

574-
all_time = _format_commit_authors_for_v3(
575-
list(base_context.get("previous_contributors", [])), "Contributor"
576-
)
557+
all_time = [
558+
a.to_v3_profile_dict("Contributor")
559+
for a in base_context.get("previous_contributors", [])
560+
]
577561
context["all_time_contributors"] = (
578562
all_time or SharedResources.library_all_contributors
579563
)

0 commit comments

Comments
 (0)