|
1 | 1 | # -*- coding: utf-8 -*-
|
| 2 | +"""Issue events logic.""" |
2 | 3 | from __future__ import unicode_literals
|
3 | 4 |
|
4 | 5 | from .. import users
|
5 | 6 | from ..models import GitHubCore
|
6 | 7 |
|
7 | 8 |
|
8 | 9 | class IssueEvent(GitHubCore):
|
9 |
| - """The :class:`IssueEvent <IssueEvent>` object. This specifically deals |
10 |
| - with events described in the |
11 |
| - `Issues\>Events <http://developer.github.com/v3/issues/events>`_ section of |
12 |
| - the GitHub API. |
| 10 | + """Representation of an event from a specific issue. |
13 | 11 |
|
14 |
| - Two event instances can be checked like so:: |
| 12 | + This object will be instantiated from calling |
| 13 | + :meth:`~github3.issues.issue.Issue.events` which calls |
| 14 | + https://developer.github.com/v3/issues/events/#list-events-for-an-issue |
15 | 15 |
|
16 |
| - e1 == e2 |
17 |
| - e1 != e2 |
| 16 | + See also: http://developer.github.com/v3/issues/events |
18 | 17 |
|
19 |
| - And is equivalent to:: |
| 18 | + This object has the following attributes: |
20 | 19 |
|
21 |
| - e1.commit_id == e2.commit_id |
22 |
| - e1.commit_id != e2.commit_id |
| 20 | + .. attribute:: actor |
23 | 21 |
|
24 |
| - """ |
25 |
| - def _update_attributes(self, event): |
26 |
| - # The type of event: |
27 |
| - # ('closed', 'reopened', 'subscribed', 'merged', 'referenced', |
28 |
| - # 'mentioned', 'assigned') |
29 |
| - #: The type of event, e.g., closed |
30 |
| - self.event = self._get_attribute(event, 'event') |
31 |
| - #: SHA of the commit. |
32 |
| - self.commit_id = self._get_attribute(event, 'commit_id') |
33 |
| - self._api = self._get_attribute(event, 'url') |
34 |
| - |
35 |
| - #: :class:`ShortIssue <github3.issues.ShortIssue>` where this comment |
36 |
| - #: was made. |
37 |
| - from .issue import ShortIssue |
38 |
| - self.issue = self._class_attribute(event, 'issue', ShortIssue, self) |
39 |
| - |
40 |
| - #: :class:`User <github3.users.ShortUser>` who caused this event. |
41 |
| - self.actor = self._class_attribute( |
42 |
| - event, 'actor', users.ShortUser, self, |
43 |
| - ) |
| 22 | + A :class:`~github3.users.ShortUser` representing the user who |
| 23 | + generated this event. |
44 | 24 |
|
45 |
| - #: Number of comments |
46 |
| - self.comments = self._get_attribute(event, 'comments') |
| 25 | + .. attribute:: commit_id |
47 | 26 |
|
48 |
| - #: datetime object representing when the event was created. |
49 |
| - self.created_at = self._strptime_attribute(event, 'created_at') |
| 27 | + The string SHA of a commit that referenced the parent issue. If there |
| 28 | + was no commit referencing this issue, then this will be ``None``. |
50 | 29 |
|
51 |
| - #: Dictionary of links for the pull request |
52 |
| - self.pull_request = self._get_attribute(event, 'pull_request', {}) |
| 30 | + .. attribute:: commit_url |
53 | 31 |
|
54 |
| - #: Dictionary containing label details |
55 |
| - self.label = self._get_attribute(event, 'label', {}) |
| 32 | + The URL to retrieve commit information from the API for the commit |
| 33 | + that references the parent issue. If there was no commit, this will be |
| 34 | + ``None``. |
56 | 35 |
|
57 |
| - #: The integer ID of the event |
58 |
| - self.id = self._get_attribute(event, 'id') |
| 36 | + .. attribute:: created_at |
59 | 37 |
|
60 |
| - #: :class:`User <github3.users.User>` that is assigned |
61 |
| - self.assignee = self._class_attribute( |
62 |
| - event, 'assignee', users.ShortUser, self, |
63 |
| - ) |
| 38 | + A :class:`~datetime.datetime` object representing the date and time |
| 39 | + this event occurred. |
| 40 | +
|
| 41 | + .. attribute:: event |
| 42 | +
|
| 43 | + The issue-specific action that generated this event. Some examples |
| 44 | + are: |
64 | 45 |
|
65 |
| - #: Dictionary containing milestone details |
66 |
| - self.milestone = self._get_attribute(event, 'milestone', {}) |
| 46 | + - closed |
| 47 | + - reopened |
| 48 | + - subscribed |
| 49 | + - merged |
| 50 | + - referenced |
| 51 | + - mentioned |
| 52 | + - assigned |
67 | 53 |
|
68 |
| - #: Dictionary containing to and from attributes |
69 |
| - self.rename = self._get_attribute(event, 'rename', {}) |
| 54 | + See `this list of events`_ for a full listing. |
70 | 55 |
|
| 56 | + .. attribute:: id |
| 57 | +
|
| 58 | + The unique identifier for this event. |
| 59 | +
|
| 60 | + .. _this list of events: |
| 61 | + https://developer.github.com/v3/issues/events/#events-1 |
| 62 | + """ |
| 63 | + |
| 64 | + def _update_attributes(self, event): |
| 65 | + self._api = event['url'] |
| 66 | + self.actor = users.ShortUser(event['actor'], self) |
| 67 | + self.commit_id = event['commit_id'] |
| 68 | + self.commit_url = event['commit_url'] |
| 69 | + self.created_at = event['created_at'] |
| 70 | + self.event = event['event'] |
| 71 | + self.id = self._get_attribute(event, 'id') |
71 | 72 | self._uniq = self.commit_id
|
72 | 73 |
|
73 | 74 | def _repr(self):
|
74 | 75 | return '<Issue Event [{0} by {1}]>'.format(
|
75 | 76 | self.event, self.actor
|
76 | 77 | )
|
| 78 | + |
| 79 | + |
| 80 | +class RepositoryIssueEvent(IssueEvent): |
| 81 | + """Representation of an issue event on the repository level. |
| 82 | +
|
| 83 | + This object will be instantiated from calling |
| 84 | + :meth:`~github3.repos.repo.Repository.issue_events` or |
| 85 | + :meth:`~github3.repos.repo.ShortRepository.issue_events`which call |
| 86 | + https://developer.github.com/v3/issues/events/#list-events-for-a-repository |
| 87 | +
|
| 88 | + See also: http://developer.github.com/v3/issues/events |
| 89 | +
|
| 90 | + This object has all of the attributes of |
| 91 | + :class:`~github3.issues.event.IssueEvent` and the following: |
| 92 | +
|
| 93 | + .. attribute:: issue |
| 94 | +
|
| 95 | + A :class:`~github3.issues.issue.ShortIssue` representing the issue |
| 96 | + where this event originated from. |
| 97 | +
|
| 98 | + """ |
| 99 | + |
| 100 | + def _update_attributes(self, event): |
| 101 | + super(RepositoryIssueEvent, self)._update_attributes(event) |
| 102 | + from . import issue |
| 103 | + self.issue = issue.ShortIssue(event['issue'], self) |
| 104 | + |
| 105 | + def _repr(self): |
| 106 | + return '<Repository Issue Event on #{} [{} by {}]>'.format( |
| 107 | + self.issue.number, self.event, self.actor.login |
| 108 | + ) |
0 commit comments