Skip to content

Commit 24fca7f

Browse files
authored
Verified GitHub stats (#16532)
* Only show GitHub statistics if verified URL * Add a link to the verified repo * Style unverified section correctly * Move meta section into a list * Update translations * Remove list-style formatting * Format meta section with indentation * Separate tests for None * Update translations
1 parent 6ab6250 commit 24fca7f

File tree

6 files changed

+160
-112
lines changed

6 files changed

+160
-112
lines changed

tests/unit/packaging/test_models.py

+24-10
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,8 @@ def test_acl(self, db_session):
784784
)
785785

786786
@pytest.mark.parametrize(
787-
("home_page", "expected"),
787+
("url", "expected"),
788788
[
789-
(None, None),
790789
(
791790
"https://github.com/pypi/warehouse",
792791
"https://api.github.com/repos/pypi/warehouse",
@@ -819,14 +818,21 @@ def test_acl(self, db_session):
819818
("[email protected]:definex/dsgnutils.git", None),
820819
],
821820
)
822-
def test_github_repo_info_url(self, db_session, home_page, expected):
823-
release = DBReleaseFactory.create(home_page=home_page)
824-
assert release.github_repo_info_url == expected
821+
def test_verified_github_repo_info_url(self, db_session, url, expected):
822+
release = DBReleaseFactory.create()
823+
release.project_urls["Homepage"] = {"url": url, "verified": True}
824+
assert release.verified_github_repo_info_url == expected
825+
826+
def test_verified_github_repo_info_url_is_none_without_verified_url(
827+
self,
828+
db_session,
829+
):
830+
release = DBReleaseFactory.create()
831+
assert release.verified_github_repo_info_url is None
825832

826833
@pytest.mark.parametrize(
827-
("home_page", "expected"),
834+
("url", "expected"),
828835
[
829-
(None, None),
830836
(
831837
"https://github.com/pypi/warehouse",
832838
"https://api.github.com/search/issues?q=repo:pypi/warehouse"
@@ -864,9 +870,17 @@ def test_github_repo_info_url(self, db_session, home_page, expected):
864870
),
865871
],
866872
)
867-
def test_github_open_issue_info_url(self, db_session, home_page, expected):
868-
release = DBReleaseFactory.create(home_page=home_page)
869-
assert release.github_open_issue_info_url == expected
873+
def test_verified_github_open_issue_info_url(self, db_session, url, expected):
874+
release = DBReleaseFactory.create()
875+
release.project_urls["Homepage"] = {"url": url, "verified": True}
876+
assert release.verified_github_open_issue_info_url == expected
877+
878+
def test_verified_github_open_issueo_info_url_is_none_without_verified_url(
879+
self,
880+
db_session,
881+
):
882+
release = DBReleaseFactory.create()
883+
assert release.verified_github_open_issue_info_url is None
870884

871885
def test_trusted_published_none(self, db_session):
872886
release = DBReleaseFactory.create()

warehouse/locale/messages.pot

+31-27
Original file line numberDiff line numberDiff line change
@@ -2807,74 +2807,78 @@ msgid "Verified details"
28072807
msgstr ""
28082808

28092809
#: warehouse/templates/includes/packaging/project-data.html:19
2810-
#: warehouse/templates/includes/packaging/project-data.html:67
2810+
#: warehouse/templates/includes/packaging/project-data.html:114
28112811
msgid "Project links"
28122812
msgstr ""
28132813

2814-
#: warehouse/templates/includes/packaging/project-data.html:46
2815-
msgid "Maintainers"
2816-
msgstr ""
2817-
2818-
#: warehouse/templates/includes/packaging/project-data.html:48
2819-
msgid "Avatar for {username} from gravatar.com"
2820-
msgstr ""
2821-
2822-
#: warehouse/templates/includes/packaging/project-data.html:64
2823-
msgid "Unverified details"
2814+
#: warehouse/templates/includes/packaging/project-data.html:47
2815+
msgid "GitHub Statistics"
28242816
msgstr ""
28252817

2826-
#: warehouse/templates/includes/packaging/project-data.html:82
2827-
msgid "GitHub Statistics"
2818+
#: warehouse/templates/includes/packaging/project-data.html:53
2819+
msgid "Repository"
28282820
msgstr ""
28292821

2830-
#: warehouse/templates/includes/packaging/project-data.html:89
2822+
#: warehouse/templates/includes/packaging/project-data.html:60
28312823
msgid "Stars:"
28322824
msgstr ""
28332825

2834-
#: warehouse/templates/includes/packaging/project-data.html:97
2826+
#: warehouse/templates/includes/packaging/project-data.html:68
28352827
msgid "Forks:"
28362828
msgstr ""
28372829

2838-
#: warehouse/templates/includes/packaging/project-data.html:105
2830+
#: warehouse/templates/includes/packaging/project-data.html:76
28392831
msgid "Open issues:"
28402832
msgstr ""
28412833

2842-
#: warehouse/templates/includes/packaging/project-data.html:113
2834+
#: warehouse/templates/includes/packaging/project-data.html:84
28432835
msgid "Open PRs:"
28442836
msgstr ""
28452837

2846-
#: warehouse/templates/includes/packaging/project-data.html:123
2838+
#: warehouse/templates/includes/packaging/project-data.html:93
2839+
msgid "Maintainers"
2840+
msgstr ""
2841+
2842+
#: warehouse/templates/includes/packaging/project-data.html:95
2843+
msgid "Avatar for {username} from gravatar.com"
2844+
msgstr ""
2845+
2846+
#: warehouse/templates/includes/packaging/project-data.html:111
2847+
msgid "Unverified details"
2848+
msgstr ""
2849+
2850+
#: warehouse/templates/includes/packaging/project-data.html:130
28472851
msgid "Meta"
28482852
msgstr ""
28492853

2850-
#: warehouse/templates/includes/packaging/project-data.html:125
2854+
#: warehouse/templates/includes/packaging/project-data.html:135
28512855
msgid "License:"
28522856
msgstr ""
28532857

2854-
#: warehouse/templates/includes/packaging/project-data.html:128
2855-
#: warehouse/templates/includes/packaging/project-data.html:130
2858+
#: warehouse/templates/includes/packaging/project-data.html:142
2859+
#: warehouse/templates/includes/packaging/project-data.html:148
28562860
msgid "Author:"
28572861
msgstr ""
28582862

2859-
#: warehouse/templates/includes/packaging/project-data.html:133
2860-
#: warehouse/templates/includes/packaging/project-data.html:135
2863+
#: warehouse/templates/includes/packaging/project-data.html:155
2864+
#: warehouse/templates/includes/packaging/project-data.html:161
28612865
#: warehouse/templates/pages/help.html:612
28622866
msgid "Maintainer:"
28632867
msgstr ""
28642868

2865-
#: warehouse/templates/includes/packaging/project-data.html:140
2869+
#: warehouse/templates/includes/packaging/project-data.html:169
28662870
msgid "Tags"
28672871
msgstr ""
28682872

2869-
#: warehouse/templates/includes/packaging/project-data.html:150
2873+
#: warehouse/templates/includes/packaging/project-data.html:181
28702874
msgid "Requires:"
28712875
msgstr ""
28722876

2873-
#: warehouse/templates/includes/packaging/project-data.html:155
2877+
#: warehouse/templates/includes/packaging/project-data.html:188
28742878
msgid "Provides-Extra:"
28752879
msgstr ""
28762880

2877-
#: warehouse/templates/includes/packaging/project-data.html:163
2881+
#: warehouse/templates/includes/packaging/project-data.html:198
28782882
#: warehouse/templates/pages/classifiers.html:16
28792883
#: warehouse/templates/pages/classifiers.html:21
28802884
#: warehouse/templates/pages/sitemap.html:39

warehouse/packaging/models.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,9 @@ def urls_by_verify_status(self, verified: bool):
704704
_urls[name] = url
705705
return _urls
706706

707-
@staticmethod
708-
def get_user_name_and_repo_name(urls):
709-
for url in urls:
707+
@property
708+
def verified_user_name_and_repo_name(self):
709+
for _, url in self.urls_by_verify_status(True).items():
710710
try:
711711
parsed = parse_url(url)
712712
except LocationParseError:
@@ -722,14 +722,14 @@ def get_user_name_and_repo_name(urls):
722722
return None, None
723723

724724
@property
725-
def github_repo_info_url(self):
726-
user_name, repo_name = self.get_user_name_and_repo_name(self.urls.values())
725+
def verified_github_repo_info_url(self):
726+
user_name, repo_name = self.verified_user_name_and_repo_name
727727
if user_name and repo_name:
728728
return f"https://api.github.com/repos/{user_name}/{repo_name}"
729729

730730
@property
731-
def github_open_issue_info_url(self):
732-
user_name, repo_name = self.get_user_name_and_repo_name(self.urls.values())
731+
def verified_github_open_issue_info_url(self):
732+
user_name, repo_name = self.verified_user_name_and_repo_name
733733
if user_name and repo_name:
734734
return (
735735
f"https://api.github.com/search/issues?q=repo:{user_name}/{repo_name}"

warehouse/static/sass/blocks/_verified.scss

+3-8
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,14 @@
1818
<div class="verified"></div>
1919
*/
2020

21-
.verified {
21+
.verified, .unverified {
2222
ul {
2323
padding-top: 0;
2424
}
2525

2626
li {
27-
list-style-type: circle;
28-
list-style-position: inside;
29-
padding-left: 20;
30-
3127
a {
3228
display: inline;
33-
padding: 0;
3429
}
3530
}
3631

@@ -39,8 +34,8 @@
3934
}
4035

4136
h6 {
42-
padding-bottom: 5;
43-
padding-top: 15;
37+
padding-bottom: 5px;
38+
padding-top: 15px;
4439
}
4540

4641
small {

0 commit comments

Comments
 (0)