8000 Add additional starred_at attribute for repository · pythonthings/github3.py@de98533 · GitHub
[go: up one dir, main page]

Skip to content

Commit de98533

Browse files
Add additional starred_at attribute for repository
This is only retrieved on github3.users.User.starred_repositories call
1 parent 0632f6a commit de98533

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

github3/repos/repo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class Repository(GitHubCore):
5959
6060
"""
6161

62+
STAR_HEADERS = {
63+
'Accept': 'application/vnd.github.v3.star+json'
64+
}
65+
6266
def _update_attributes(self, repo):
6367
#: URL used to clone via HTTPS.
6468
self.clone_url = repo.get('clone_url', '')
@@ -142,6 +146,9 @@ def _update_attributes(self, repo):
142146
#: Number of users who starred the repository
143147
self.stargazers_count = repo.get('stargazers_count', 0)
144148

149+
#: ``datetime`` object representing when the repository was starred
150+
self.starred_at = self._strptime(repo.get('starred_at'))
151+
145152
# SSH url e.g. git@github.com/sigmavirus24/github3.py
146153
#: URL to clone the repository via SSH.
147154
self.ssh_url = repo.get('ssh_url', '')

github3/users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ def starred_repositories(self, sort=None, direction=None, number=-1,
387387
params = {'sort': sort, 'direction': direction}
388388
self._remove_none(params)
389389
url = self.starred_urlt.expand(owner=None, repo=None)
390-
return self._iter(int(number), url, Repository, params, etag)
390+
return self._iter(int(number), url, Repository, params, etag,
391+
headers=Repository.STAR_HEADERS)
391392

392393
def subscriptions(self, number=-1, etag=None):
393394
"""Iterate over repositories subscribed to by this user.

tests/cassettes/User_starred_repositories.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/integration/test_users.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Integration tests for the User class."""
22
import github3
3+
import datetime
34

45
from .helper import IntegrationHelper
56

@@ -93,6 +94,7 @@ def test_starred_repositories(self):
9394
assert len(repos) > 0
9495
for starred in repos:
9596
assert isinstance(starred, github3.repos.Repository)
97+
assert isinstance(starred.starred_at, datetime.datetime)
9698

9799
def test_subscriptions(self):
98100
"""Show that a user can retrieve the repos subscribed to by a user."""

0 commit comments

Comments
 (0)
0