Skip to content

Commit 92bf52b

Browse files
committed
Merge pull request sigmavirus24#221 from bgilbert/attributes
Attribute improvements
2 parents fcf42bd + 3e2d0f6 commit 92bf52b

16 files changed

Lines changed: 37 additions & 59 deletions

File tree

github3/auths.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ def __init__(self, auth, session=None):
4848
self.id = auth.get('id', 0)
4949
self._api = self._build_url('authorizations', str(self.id))
5050
#: datetime object representing when the authorization was created.
51-
self.created_at = None
52-
if auth.get('created_at'):
53-
self.created_at = self._strptime(auth.get('created_at'))
54-
#: datetime object representing when the authorization was created.
55-
self.updated_at = None
56-
if auth.get('updated_at'):
57-
self.updated_at = self._strptime(auth.get('updated_at'))
51+
self.created_at = self._strptime(auth.get('created_at'))
52+
#: datetime object representing when the authorization was updated.
53+
self.updated_at = self._strptime(auth.get('updated_at'))
5854

5955
def _repr(self):
6056
return '<Authorization [{0}]>'.format(self.name)

github3/gists/gist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, data, session=None):
7676

7777
owner = data.get('owner')
7878
#: :class:`User <github3.users.User>` object representing the owner of
79-
# the gist.
79+
#: the gist.
8080
self.owner = User(owner, self) if owner else None
8181

8282
self._files = [GistFile(data['files'][f]) for f in data['files']]

github3/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, commit, session=None):
7676
super(Commit, self).__init__(commit, session)
7777

7878
#: dict containing at least the name, email and date the commit was
79-
# created
79+
#: created
8080
self.author = commit.get('author', {}) or {}
8181
# If GH returns nil/None then make sure author is a dict
8282
self._author_name = self.author.get('name', '')

github3/issues/event.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import unicode_literals
33

44
from github3.models import GitHubCore
5+
from github3.users import User
56

67

78
class IssueEvent(GitHubCore):
@@ -38,6 +39,11 @@ def __init__(self, event, issue=None):
3839
from github3.issues import Issue
3940
self.issue = Issue(event.get('issue'), self)
4041

42+
#: :class:`User <github3.users.User>` that generated the event.
43+
self.actor = event.get('actor')
44+
if self.actor:
45+
self.actor = User(self.actor, self._session)
46+
4147
#: Number of comments
4248
self.comments = event.get('comments', 0)
4349

github3/issues/issue.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, issue, session=None):
3535
super(Issue, self).__init__(issue, session)
3636
self._api = issue.get('url', '')
3737
#: :class:`User <github3.users.User>` representing the user the issue
38-
# was assigned to.
38+
#: was assigned to.
3939
self.assignee = issue.get('assignee')
4040
if self.assignee:
4141
self.assignee = User(issue.get('assignee'), self._session)
@@ -48,9 +48,7 @@ def __init__(self, issue, session=None):
4848

4949
# If an issue is still open, this field will be None
5050
#: datetime object representing when the issue was closed.
51-
self.closed_at = None
52-
if issue.get('closed_at'):
53-
self.closed_at = self._strptime(issue.get('closed_at'))
51+
self.closed_at = self._strptime(issue.get('closed_at'))
5452

5553
#: Number of comments on this issue.
5654
self.comments = issue.get('comments')

github3/issues/milestone.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ def __init__(self, mile, session=None):
2626
#: Description of this milestone.
2727
self.description = mile.get('description')
2828
#: :class:`User <github3.users.User>` object representing the creator
29-
# of the milestone.
29+
#: of the milestone.
3030
self.creator = User(mile.get('creator'), self._session)
3131
#: Number of issues associated with this milestone which are still
32-
# open.
32+
#: open.
3333
self.open_issues = mile.get('open_issues')
3434
#: The number of closed issues associated with this milestone.
3535
self.closed_issues = mile.get('closed_issues')
3636
#: datetime object representing when the milestone was created.
3737
self.created_at = self._strptime(mile.get('created_at'))
3838
#: datetime representing when this milestone is due.
39-
self.due_on = None
40-
if mile.get('due_on'):
41-
self.due_on = self._strptime(mile.get('due_on'))
39+
self.due_on = self._strptime(mile.get('due_on'))
40+
#: datetime object representing when the milestone was updated.
41+
self.updated_at = self._strptime(mile.get('updated_at'))
4242

4343
def _repr(self):
4444
return '<Milestone [{0}]>'.format(self)

github3/models.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def __init__(self, comment, session):
229229
#: Body of the comment. (As written by the commenter)
230230
self.body = comment.get('body')
231231
#: Body of the comment formatted as plain-text. (Stripped of markdown,
232-
# etc.)
232+
#: etc.)
233233
self.body_text = comment.get('body_text')
234234
#: Body of the comment formatted as html.
235235
self.body_html = comment.get('body_html')
@@ -319,9 +319,7 @@ def __init__(self, acct, session):
319319
self.company = acct.get('company', '')
320320

321321
#: datetime object representing the date the account was created
322-
self.created_at = None
323-
if acct.get('created_at'):
324-
self.created_at = self._strptime(acct.get('created_at'))
322+
self.created_at = self._strptime(acct.get('created_at'))
325323

326324
#: E-mail address of the user/org
327325
self.email = acct.get('email')

github3/notifications.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def __init__(self, notif, session=None):
4949
#: Dictionary of urls for the thread
5050
self.urls = notif.get('urls')
5151
#: datetime object representing the last time the user read the thread
52-
self.last_read_at = notif.get('last_read_at')
53-
if self.last_read_at:
54-
self.last_read_at = self._strptime(self.last_read_at)
52+
self.last_read_at = self._strptime(notif.get('last_read_at'))
5553
#: The reason you're receiving the notification
5654
self.reason = notif.get('reason')
5755
#: Subject of the Notification, e.g., which issue/pull/diff is this in

github3/pulls.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ def __init__(self, pull, session=None):
112112
#: Number of deletions on this pull request
113113
self.deletions = pull.get('deletions')
114114

115-
closed = pull.get('closed_at')
116-
# If the pull request has been closed
117115
#: datetime object representing when the pull was closed
118-
self.closed_at = self._strptime(closed) if closed else None
116+
self.closed_at = self._strptime(pull.get('closed_at'))
119117
#: Number of comments
120118
self.comments = pull.get('comments')
121119
#: Comments url (not a template)
@@ -162,9 +160,7 @@ def __init__(self, pull, session=None):
162160
}
163161

164162
#: datetime object representing when the pull was merged
165-
merged = pull.get('merged_at')
166-
# If the pull request has been merged
167-
self.merged_at = self._strptime(merged) if merged else None
163+
self.merged_at = self._strptime(pull.get('merged_at'))
168164
#: Whether the pull is deemed mergeable by GitHub
169165
self.mergeable = pull.get('mergeable', False)
170166
#: Whether it would be a clean merge or not
@@ -198,12 +194,12 @@ def __init__(self, pull, session=None):
198194
#: datetime object representing the last time the object was changed
199195
self.updated_at = self._strptime(pull.get('updated_at'))
200196
#: :class:`User <github3.users.User>` object representing the creator
201-
# of the pull request
197+
#: of the pull request
202198
self.user = pull.get('user')
203199
if self.user:
204200
self.user = User(self.user, self)
205201
#: :class:`User <github3.users.User>` object representing the assignee
206-
# of the pull request
202+
#: of the pull request
207203
self.assignee = pull.get('assignee')
208204
if self.assignee:
209205
self.assignee = User(self.assignee, self)

github3/repos/branch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, branch, session=None):
1515
#: Name of the branch.
1616
self.name = branch.get('name')
1717
#: Returns the branch's :class:`RepoCommit <RepoCommit>` or
18-
# ``None``.
18+
#: ``None``.
1919
self.commit = branch.get('commit')
2020
if self.commit:
2121
self.commit = RepoCommit(self.commit, self._session)

0 commit comments

Comments
 (0)