8000 Re-organize repos as well · davidmoss/github3.py@4f92dce · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f92dce

Browse files
committed
Re-organize repos as well
And fix RepoComment.update
1 parent 78d1ee1 commit 4f92dce

File tree

13 files changed

+304
-291
lines changed

13 files changed

+304
-291
lines changed

HISTORY.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ History/Changelog
2525

2626
- Remove vendored dependency of PySO8601.
2727

28-
- Split `GitHub.iter_repos` into `GitHub.iter_user_repos` and
29-
`GitHub.iter_repos`. As a consequence `github3.iter_repos` is now
30-
`github3.iter_user_repos`
28+
- Split ``GitHub.iter_repos`` into ``GitHub.iter_user_repos`` and
29+
``GitHub.iter_repos``. As a consequence ``github3.iter_repos`` is now
30+
``github3.iter_user_repos``
31+
32+
- ``IssueComment.update`` was corrected to match GitHub's documentation
3133

3234
0.5.3: 2013-03-19
3335
-----------------

github3/events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ def _gist(payload):
9595

9696

9797
def _issuecomm(payload):
98-
from github3.issues import Issue, IssueComment
98+
from github3.issues import Issue
99+
from github3.issues.comment import IssueComment
99100
if payload.get('issue'):
100101
payload['issue'] = Issue(payload['issue'], None)
101102
if payload.get('comment'):

github3/issues/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
github3.issues
3+
==============
4+
5+
This module contains the classes related to issues.
6+
7+
See also: http://developer.github.com/v3/issues/
8+
"""
9+
10+
from re import match
11+
from .issue import Issue # NOQA
12+
13+
14+
def issue_params(filter, state, labels, sort, direction, since):
15+
params = {}
16+
if filter in ('assigned', 'created', 'mentioned', 'subscribed'):
17+
params['filter'] = filter
18+
19+
if state in ('open', 'closed'):
20+
params['state'] = state
21+
22+
if labels:
23+
params['labels'] = labels
24+
25+
if sort in ('created', 'updated', 'comments'):
26+
params['sort'] = sort
27+
28+
if direction in ('asc', 'desc'):
29+
params['direction'] = direction
30+
31+
if since and match('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$', since):
32+
params['since'] = since
33+
34+
return params

github3/issues/comment.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from github3.models import BaseComment
2+
from github3.users import User
3+
4+
5+
class IssueComment(BaseComment):
6+
"""The :class:`IssueComment <IssueComment>` object. This structures and
7+
handles the comments on issues specifically.
8+
9+
See also: http://developer.github.com/v3/issues/comments/
10+
"""
11+
def __init__(self, comment, session=None):
12+
super(IssueComment, self).__init__(comment, session)
13+
14+
#: :class:`User <github3.users.User>` who made the comment
15+
self.user = None
16+
if comment.get('user'):
17+
self.user = User(comment.get('user'), self)
18+
19+
def __repr__(self):
20+
return '<Issue Comment [{0}]>'.format(self.user.login)

github3/issues/event.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from github3.models import GitHubCore
2+
3+
4+
class IssueEvent(GitHubCore):
5+
"""The :class:`IssueEvent <IssueEvent>` object. This specifically deals
6+
with events described in the
7+
`Issues\>Events <http://developer.github.com/v3/issues/events>`_ section of
8+
the GitHub API.
9+
"""
10+
def __init__(self, event, issue=None):
11+
super(IssueEvent, self).__init__(event, None)
12+
# The type of event:
13+
# ('closed', 'reopened', 'subscribed', 'merged', 'referenced',
14+
# 'mentioned', 'assigned')
15+
#: The type of event, e.g., closed
16+
self.event = event.get('event')
17+
#: SHA of the commit.
18+
self.commit_id = event.get('commit_id')
19+
self._api = event.get('url', '')
20+
21+
#: :class:`Issue <github3.issue.Issue>` where this comment was made.
22+
self.issue = issue
23+
if event.get('issue'):
24+
from github3.issues import Issue
25+
self.issue = Issue(event.get('issue'), self)
26+
27+
#: Number of comments
28+
self.comments = event.get('comments', 0)
29+
30+
#: datetime object representing when the event was created.
31+
self.created_at = self._strptime(event.get('created_at'))
32+
33+
#: Dictionary of links for the pull request
34+
self.pull_request = event.get('pull_request', {})
35+
36+
def __repr__(self):
37+
return '<Issue Event [#{0} - {1}]>'.format(
38+
self.issue.number, self.event
39+
)

github3/issues.py renamed to github3/issues/issue.py

Lines changed: 6 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,12 @@
1-
"""
2-
github3.issues
3-
==============
4-
5-
This module contains the classes related to issues.
6-
7-
"""
8-
91
from re import match
102
from json import dumps
11-
from github3.models import GitHubCore, BaseComment
12-
from github3.users import User
133
from github3.decorators import requires_auth
14-
15-
16-
class Label(GitHubCore):
17-
"""The :class:`Label <Label>` object. Succintly represents a label that
18-
exists in a repository."""
19-
def __init__(self, label, session=None):
20-
super(Label, self).__init__(label, session)
21-
self._api = label.get('url', '')
22-
#: Color of the label, e.g., 626262
23-
self.color = label.get('color')
24-
#: Name of the label, e.g., 'bug'
25-
self.name = label.get('name')
26-
27-
def __repr__(self):
28-
return '<Label [{0}]>'.format(self)
29-
30-
def __str__(self):
31-
return self.name
32-
33-
def _update_(self, label):
34-
self.__init__(label, self._session)
35-
36-
@requires_auth
37-
def delete(self):
38-
"""Delete this label.
39-
40-
:returns: bool
41-
"""
42-
return self._boolean(self._delete(self._api), 204, 404)
43-
44-
@requires_auth
45-
def update(self, name, color):
46-
"""Update this label.
47-
48-
:param str name: (required), new name of the label
49-
:param str color: (required), color code, e.g., 626262, no leading '#'
50-
:returns: bool
51-
"""
52-
json = None
53-
54-
if name and color:
55-
if color[0] == '#':
56-
color = color[1:]
57-
json = self._json(self._patch(self._api, data=dumps({
58-
'name': name, 'color': color})), 200)
59-
60-
if json:
61-
self._update_(json)
62-
return True
63-
64-
return False
65-
66-
67-
class Milestone(GitHubCore):
68-
"""The :class:`Milestone <Milestone>` object. This is a small class to
69-
handle information about milestones on repositories and issues.
70-
"""
71-
def __init__(self, mile, session=None):
72-
super(Milestone, self).__init__(mile, session)
1241 73-
self._api = mile.get('url', '')
74-
#: Identifying number associated with milestone.
75-
self.number = mile.get('number')
7 F438 6-
#: State of the milestone, e.g., open or closed.
77-
self.state = mile.get('state')
78-
#: Title of the milestone, e.g., 0.2.
79-
self.title = mile.get('title')
80-
#: Description of this milestone.
81-
self.description = mile.get('description')
82-
#: :class:`User <github3.users.User>` object representing the creator
83-
# of the milestone.
84-
self.creator = User(mile.get('creator'), self._session)
85-
#: Number of issues associated with this milestone which are still
86-
# open.
87-
self.open_issues = mile.get('open_issues')
88-
#: The number of closed issues associated with this milestone.
89-
self.closed_issues = mile.get('closed_issues')
90-
#: datetime object representing when the milestone was created.
91-
self.created_at = self._strptime(mile.get('created_at'))
92-
#: datetime representing when this milestone is due.
93-
self.due_on = None
94-
if mile.get('due_on'):
95-
self.due_on = self._strptime(mile.get('due_on'))
96-
97-
def __repr__(self):
98-
return '<Milestone [{0}]>'.format(self)
99-
100-
def __str__(self):
101-
return self.title
102-
103-
def _update_(self, mile):
104-
self.__init__(mile, self._session)
105-
106-
@requires_auth
107-
def delete(self):
108-
"""Delete this milestone.
109-
110-
:returns: bool
111-
"""
112-
return self._boolean(self._delete(self._api), 204, 404)
113-
114-
def iter_labels(self, number=-1):
115-
"""Iterate over the labels for every issue associated with this
116-
milestone.
117-
118-
:param int number: (optional), number of labels to return. Default: -1
119-
returns all available labels.
120-
:returns: generator of :class:`Label <Label>`\ s
121-
"""
122-
url = self._build_url('labels', base_url=self._api)
123-
return self._iter(int(number), url, Label)
124-
125-
@requires_auth
126-
def update(self, title, state='', description='', due_on=''):
127-
"""Update this milestone.
128-
129-
state, description, and due_on are optional
130-
131-
:param str title: (required), new title of the milestone
132-
:param str state: (optional), ('open', 'closed')
133-
:param str description: (optional)
134-
:param str due_on: (optional), ISO 8601 time format:
135-
YYYY-MM-DDTHH:MM:SSZ
136-
:returns: bool
137-
"""
138-
data = {'title': title, 'state': state,
139-
'description': description, 'due_on': due_on}
140-
json = None
141-
142-
if title:
143-
json = self._json(self._patch(self._api, data=dumps(data)), 200)
144-
if json:
145-
self._update_(json)
146-
return True
147-
return False
4+
from github3.issues.comment import IssueComment
5+
from github3.issues.event import IssueEvent
6+
from github3.issues.label import Label
7+
from github3.issues.milestone import Milestone
8+
from github3.models import GitHubCore
9+
from github3.users import User
14810

14911

15012
class Issue(GitHubCore):
@@ -379,79 +241,3 @@ def reopen(self):
379241
number = self.milestone.number if self.milestone else None
380242
return self.edit(self.title, self.body, assignee, 'open',
381243
number, self.labels)
382-
383-
384-
class IssueComment(BaseComment):
385-
"""The :class:`IssueComment <IssueComment>` object. This structures and
386-
handles the comments on issues specifically.
387-
"""
388-
def __init__(self, comment, session=None):
389-
super(IssueComment, self).__init__(comment, session)
390-
391-
#: :class:`User <github3.users.User>` who made the comment
392-
self.user = None
393-
if comment.get('user'):
394-
self.user = User(comment.get('user'), self)
395-
396-
def __repr__(self):
397-
return '<Issue Comment [{0}]>'.format(self.user.login)
398-
399-
400-
class IssueEvent(GitHubCore):
401-
"""The :class:`IssueEvent <IssueEvent>` object. This specifically deals
402-
with events described in the
403-
`Issues\>Events <http://developer.github.com/v3/issues/events>`_ section of
404-
the GitHub API.
405-
"""
406-
def __init__(self, event, issue=None):
407-
super(IssueEvent, self).__init__(event, None)
408-
# The type of event:
409-
# ('closed', 'reopened', 'subscribed', 'merged', 'referenced',
410-
# 'mentioned', 'assigned')
411-
#: The type of event, e.g., closed
412-
self.event = event.get('event')
413-
#: SHA of the commit.
414-
self.commit_id = event.get('commit_id')
415-
self._api = event.get('url', '')
416-
417-
#: :class:`Issue <Issue>` where this comment was made.
418-
self.issue = issue
419-
if event.get('issue'):
420-
self.issue = Issue(event.get('issue'), self)
421-
422-
#: Number of comments
423-
self.comments = event.get('comments', 0)
424-
425< F06B /td>-
#: datetime object representing when the event was created.
426-
self.created_at = self._strptime(event.get('created_at'))
427-
428-
#: Dictionary of links for the pull request
429-
self.pull_request = event.get('pull_request', {})
430-
431-
def __repr__(self):
432-
return '<Issue Event [#{0} - {1}]>'.format(
433-
self.issue.number, self.event
434-
)
435-
436-
437-
def issue_params(filter, state, labels, sort, direction, since):
438-
params = {}
439-
if filter in ('assigned', 'created', 'mentioned', 'subscribed'):
440-
params['filter'] = filter
441-
442-
if state in ('open', 'closed'):
443-
params['state'] = state
444-
445-
if labels:
446-
params['labels'] = labels
447-
448-
if sort in ('created', 'updated', 'comments'):
449-
params['sort'] = sort
450-
451-
if direction in ('asc', 'desc'):
452-
params['direction'] = direction
453-
454-
if since and match('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$', since):
455-
params['since'] = since
456-
457-
return params

0 commit comments

Comments
 (0)
0