|
1 |
| -""" |
2 |
| -github3.issues |
3 |
| -============== |
4 |
| -
|
5 |
| -This module contains the classes related to issues. |
6 |
| -
|
7 |
| -""" |
8 |
| - |
9 | 1 | from re import match
|
10 | 2 | from json import dumps
|
11 |
| -from github3.models import GitHubCore, BaseComment |
12 |
| -from github3.users import User |
13 | 3 | 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 |
148 | 10 |
|
149 | 11 |
|
150 | 12 | class Issue(GitHubCore):
|
@@ -379,79 +241,3 @@ def reopen(self):
|
379 | 241 | number = self.milestone.number if self.milestone else None
|
380 | 242 | return self.edit(self.title, self.body, assignee, 'open',
|
381 | 243 | 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