Skip to content

Commit

Permalink
Maintainers data in json api. Fixes pypi#9978
Browse files Browse the repository at this point in the history
  • Loading branch information
peterk committed Sep 28, 2024
1 parent 1b33b28 commit c617e22
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/unit/legacy/api/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def test_renders(self, pyramid_config, db_request, db_session):
"license": None,
"maintainer": None,
"maintainer_email": None,
"maintainers": [],
"name": project.name,
"package_url": "/the/fake/url/",
"platform": None,
Expand Down Expand Up @@ -574,6 +575,7 @@ def test_detail_renders(self, pyramid_config, db_request, db_session):
"license": None,
"maintainer": None,
"maintainer_email": None,
"maintainers": [],
"name": project.name,
"package_url": "/the/fake/url/",
"platform": None,
Expand Down Expand Up @@ -666,6 +668,7 @@ def test_minimal_renders(self, pyramid_config, db_request):
"license": None,
"maintainer": None,
"maintainer_email": None,
"maintainers": [],
"name": project.name,
"package_url": "/the/fake/url/",
"platform": None,
Expand Down
21 changes: 21 additions & 0 deletions warehouse/legacy/api/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
Project,
Release,
ReleaseURL,
Role,
User,
)
from warehouse.utils.cors import _CORS_HEADERS

Expand Down Expand Up @@ -144,6 +146,24 @@ def _json_data(request, project, release, *, all_releases):
for vulnerability_record in release.vulnerabilities
]

# Serialize maintainers and their project role.
maintainers = [
{
"username": maintainer.username,
"name": maintainer.name,
"role_name": maintainer.role_name,
}
for maintainer in (
request.db.query(Role)
.join(User)
.filter(Role.project == project)
.distinct(User.username)
.order_by(User.username)
.with_entities(User.username, User.name, Role.role_name)
.all()
)
]

data = {
"info": {
"name": project.name,
Expand All @@ -158,6 +178,7 @@ def _json_data(request, project, release, *, all_releases):
"author_email": release.author_email,
"maintainer": release.maintainer,
"maintainer_email": release.maintainer_email,
"maintainers": maintainers,
"requires_python": release.requires_python,
"platform": release.platform,
"downloads": {"last_day": -1, "last_week": -1, "last_month": -1},
Expand Down

0 comments on commit c617e22

Please sign in to comment.