10000 Parse attributes on IssueEvent into objects. Fixes #820 · staticdev/github4.py@22a1bbf · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 22, 2021. It is now read-only.

Commit 22a1bbf

Browse files
committed
Parse attributes on IssueEvent into objects. Fixes sigmavirus24#820
1 parent 05ed0c6 commit 22a1bbf

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

github3/issues/event.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,27 @@ def _update_attributes(self, event):
6666
self.actor = users.ShortUser(event['actor'], self)
6767
self.commit_id = event['commit_id']
6868
self.commit_url = event['commit_url']
69-
self.created_at = event['created_at']
69+
self.created_at = self._strptime(event['created_at'])
70+
# Only for 'assigned' and 'unassigned' events.
71+
self.assignee = event.get('assignee')
72+
if self.assignee:
73+
self.assignee = users.ShortUser(self.assignee, self)
74+
self.assigner = event.get('assigner')
75+
if self.assigner:
76+
self.assigner = users.ShortUser(self.assigner, self)
77+
78+
# Only for 'review_requested' and 'review_request_removed' events.
79+
self.review_requester = event.get('review_requester')
80+
if self.review_requester:
81+
self.review_requester = (
82+
users.ShortUser(self.review_requester, self))
83+
self.requested_reviewers = event.get('requested_reviewers')
84+
if self.requested_reviewers:
85+
self.requested_reviewers = [
86+
users.ShortUser(reviewer, self)
87+
for reviewer in self.requested_reviewers
88+
]
89+
7090
self.event = event['event']
7191
self.id = event['id']
7292
self._uniq = self.commit_id
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"id": 186998693,
3+
"url": "https://api.github.com/repos/sigmavirus24/github3.py/issues/events/186998693",
4+
"actor": {
5+
"login": "sigmavirus24",
6+
"id": 240830,
7+
"avatar_url": "https://avatars3.githubusercontent.com/u/240830?v=4",
8+
"gravatar_id": "",
9+
"url": "https://api.github.com/users/sigmavirus24",
10+
"html_url": "https://github.com/sigmavirus24",
11+
"followers_url": "https://api.github.com/users/sigmavirus24/followers",
12+
"following_url": "https://api.github.com/users/sigmavirus24/following{/other_user}",
13+
"gists_url": "https://api.github.com/users/sigmavirus24/gists{/gist_id}",
14+
"starred_url": "https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}",
15+
"subscriptions_url": "https://api.github.com/users/sigmavirus24/subscriptions",
16+
"organizations_url": "https://api.github.com/users/sigmavirus24/orgs",
17+
"repos_url": "https://api.github.com/users/sigmavirus24/repos",
18+
"events_url": "https://api.github.com/users/sigmavirus24/events{/privacy}",
19+
"received_events_url": "https://api.github.com/users/sigmavirus24/received_events",
20+
"type": "User",
21+
"site_admin": false
22+
},
23+
"event": "assigned",
24+
"commit_id": null,
25+
"commit_url": null,
26+
"created_at": "2014-11-01T23:36:13Z",
27+
"assignee": {
28+
"login": "sigmavirus24",
29+
"id": 240830,
30+
"avatar_url": "https://avatars3.githubusercontent.com/u/240830?v=4",
31+
"gravatar_id": "",
32+
"url": "https://api.github.com/users/sigmavirus24",
33+
"html_url": "https://github.com/sigmavirus24",
34+
"followers_url": "https://api.github.com/users/sigmavirus24/followers",
35+
"following_url": "https://api.github.com/users/sigmavirus24/following{/other_user}",
36+
"gists_url": "https://api.github.com/users/sigmavirus24/gists{/gist_id}",
37+
"starred_url": "https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}",
38+
"subscriptions_url": "https://api.github.com/users/sigmavirus24/subscriptions",
39+
"organizations_url": "https://api.github.com/users/sigmavirus24/orgs",
40+
"repos_url": "https://api.github.com/users/sigmavirus24/repos",
41+
"events_url": "https://api.github.com/users/sigmavirus24/events{/privacy}",
42+
"received_events_url": "https://api.github.com/users/sigmavirus24/received_events",
43+
"type": "User",
44+
"site_admin": false
45+
},
46+
"assigner": {
47+
"login": "sigmavirus24",
48+
"id": 240830,
49+
"avatar_url": "https://avatars3.githubusercontent.com/u/240830?v=4",
50+
"gravatar_id": "",
51+
"url": "https://api.github.com/users/sigmavirus24",
52+
"html_url": "https://github.com/sigmavirus24",
53+
"followers_url": "https://api.github.com/users/sigmavirus24/followers",
54+
"following_url": "https://api.github.com/users/sigmavirus24/following{/other_user}",
55+
"gists_url": "https://api.github.com/users/sigmavirus24/gists{/gist_id}",
56+
"starred_url": "https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}",
57+
"subscriptions_url": "https://api.github.com/users/sigmavirus24/subscriptions",
58+
"organizations_url": "https://api.github.com/users/sigmavirus24/orgs",
59+
"repos_url": "https://api.github.com/users/sigmavirus24/repos",
60+
"events_url": "https://api.github.com/users/sigmavirus24/events{/privacy}",
61+
"received_events_url": "https://api.github.com/users/sigmavirus24/received_events",
62+
"type": "User",
63+
"site_admin": false
64+
}
65+
}

tests/unit/test_issues_issue.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
"""Unit tests for the Issue class."""
33
import github3
4+
import datetime
45
import mock
56

67
from github3.issues.label import Label
@@ -26,6 +27,9 @@
2627
get_issue_event_example_data = helper.create_example_data_helper(
2728
'issue_event_example'
2829
)
30+
get_issue_assigned_event_example_data = helper.create_example_data_helper(
31+
'issue_assigned_event_example'
32+
)
2933
get_issue_label_example_data = helper.create_example_data_helper(
3034
'issue_label_example'
3135
)
@@ -446,6 +450,21 @@ def test_repr(self):
446450
'closed', 'octocat'
447451
)
448452

453+
def test_created_at(self):
454+
"""Show that the instance has a correct created_at datetime."""
455+
expected = datetime.datetime(
456+
2011, 4, 14, 16, 0, 49, tzinfo=datetime.timezone.utc)
457+
assert self.instance.created_at == expected
458+
459+
def test_assignee(self):
460+
"""Show that assignees are correctly parsed ShortUser objects"""
461+
assigned_event = github3.issues.event.IssueEvent(
462+
get_issue_assigned_event_example_data(),
463+
self.session
464+
)
465+
assert assigned_event.assignee.login == 'sigmavirus24'
466+
assert assigned_event.assigner.login == 'sigmavirus24'
467+
449468
def test_equality(self):
450469
"""Show that two instances of IssueEvent are equal."""
451470
issue_event = github3.issues.event.IssueEvent(

0 commit comments

Comments
 (0)
0