|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -""" |
3 | | -github3.repos.status |
4 | | -==================== |
5 | | -
|
6 | | -This module contains the Status object for GitHub's commit status API |
7 | | -
|
8 | | -""" |
| 2 | +"""This module contains the Status object for GitHub's commit status API.""" |
9 | 3 | from __future__importunicode_literals |
10 | 4 |
|
| 5 | +from ..importmodels |
11 | 6 | from ..importusers |
12 | 7 |
|
13 | 8 | from ..modelsimportGitHubCore |
14 | 9 |
|
15 | 10 |
|
16 | | -classStatus(GitHubCore): |
17 | | -"""The :class:`Status <Status>` object. |
| 11 | +class_Status(models.GitHubCore): |
| 12 | +"""Representation of a status on a repository.""" |
| 13 | + |
| 14 | +class_name='_Status' |
| 15 | + |
| 16 | +def_update_attributes(self,status): |
| 17 | +self._api=status['url'] |
| 18 | +self.context=status['context'] |
| 19 | +self.created_at=self._strptime(status['created_at']) |
| 20 | +self.description=status['description'] |
| 21 | +self.id=status['id'] |
| 22 | +self.state=status['state'] |
| 23 | +self.target_url=status['target_url'] |
| 24 | +self.updated_at=self._strptime(status['updated_at']) |
| 25 | + |
| 26 | +def_repr(self): |
| 27 | +return'<{s.class_name} [{s.id}:{s.state}]>'.format(s=self) |
| 28 | + |
| 29 | + |
| 30 | +classShortStatus(_Status): |
| 31 | +"""Representation of a short status on a repository. |
18 | 32 |
|
19 | | - This represents information from the Repo Status API. |
| 33 | + .. versionadded:: 1.0.0 |
| 34 | +
|
| 35 | + This is the representation found in a |
| 36 | + :class:`~github3.repos.status.CombinedStatus` object. |
20 | 37 |
|
21 | 38 | See also: http://developer.github.com/v3/repos/statuses/ |
22 | | - """ |
23 | 39 |
|
24 | | -def_update_attributes(self,status): |
25 | | -#: A string label to differentiate this status from the status of |
26 | | -#: other systems |
27 | | -self.context=self._get_attribute(status,'context') |
| 40 | + This object has the following attributes: |
28 | 41 |
|
29 | | -#: datetime object representing the creation of the status object |
30 | | -self.created_at=self._strptime_attribute(status,'created_at') |
| 42 | + .. attribute:: context |
31 | 43 |
|
32 | | -#: :class:`User <github3.users.User>` who created the object |
33 | | -self.creator=self._class_attribute( |
34 | | -status,'creator',users.ShortUser,self |
35 | | - ) |
| 44 | + This is a string that explains the context of this status object. |
| 45 | + For example, ``'continuous-integration/travis-ci/pr'``. |
36 | 46 |
|
37 | | -#: Short description of the Status |
38 | | -self.description=self._get_attribute(status,'description') |
| 47 | + .. attribute:: created_at |
39 | 48 |
|
40 | | -#: GitHub ID forthestatus object |
41 | | -self.id=self._get_attribute(status,'id') |
| 49 | +A :class:`~datetime.datetime` object representingthedate and time |
| 50 | +when thisstatus was created. |
42 | 51 |
|
43 | | -#: State of the status, e.g., 'success', 'pending', 'failed', 'error' |
44 | | -self.state=self._get_attribute(status,'state') |
| 52 | + .. attribute:: creator |
45 | 53 |
|
46 | | -#: URL to view more information about the status |
47 | | -self.target_url=self._get_attribute(status,'target_url') |
| 54 | +A :class:`~github3.users.ShortUser` representing the user who created |
| 55 | +thisstatus. |
48 | 56 |
|
49 | | -#: datetime object representing the last time the status was updated |
50 | | -self.updated_at=self._strptime_attribute(status,'updated_at') |
| 57 | + .. attribute:: description |
51 | 58 |
|
52 | | -def_repr(self): |
53 | | -return'<Status [{s.id}:{s.state}]>'.format(s=self) |
| 59 | + A short description of the status. |
54 | 60 |
|
| 61 | + .. attribute:: id |
55 | 62 |
|
56 | | -classCombinedStatus(GitHubCore): |
57 | | -"""The :class:`CombinedStatus <CombinedStatus>` object. |
| 63 | + The unique identifier of this status object. |
| 64 | +
|
| 65 | + .. attribute:: state |
| 66 | +
|
| 67 | + The state of this status, e.g., ``'success'``, ``'pending'``, |
| 68 | + ``'failure'``. |
| 69 | +
|
| 70 | + .. attribute:: target_url |
| 71 | +
|
| 72 | + The URL to retrieve more information about this status. |
| 73 | +
|
| 74 | + .. attribute:: updated_at |
| 75 | +
|
| 76 | + A :class:`~datetime.datetime` object representing the date and time |
| 77 | + when this status was most recently updated. |
| 78 | + """ |
| 79 | + |
| 80 | +class_name='ShortStatus' |
58 | 81 |
|
59 | | - This represents combined information from the Repo Status API. |
| 82 | + |
| 83 | +classStatus(_Status): |
| 84 | +"""Representation of a full status on a repository. |
60 | 85 |
|
61 | 86 | See also: http://developer.github.com/v3/repos/statuses/ |
| 87 | +
|
| 88 | + This object has the same attributes as a |
| 89 | + :class:`~github3.repos.status.ShortStatus` as well as the following |
| 90 | + attributes: |
| 91 | +
|
| 92 | + .. attribute:: creator |
| 93 | +
|
| 94 | + A :class:`~github3.users.ShortUser` representing the user who created |
| 95 | + this status. |
62 | 96 | """ |
63 | 97 |
|
64 | | -def_update_attributes(self,combined_status): |
65 | | -#: State of the combined status, e.g., 'success', 'pending', 'failure' |
66 | | -self.state=self._get_attribute(combined_status,'state') |
| 98 | +class_name='Status' |
67 | 99 |
|
68 | | -#: ref's SHA |
69 | | -self.sha=self._get_attribute(combined_status,'sha') |
| 100 | +def_update_attributes(self,status): |
| 101 | +super(Status,self)._update_attributes(status) |
| 102 | +self.creator=users.ShortUser(status['creator'],self) |
70 | 103 |
|
71 | | -#: Total count of sub-statuses |
72 | | -self.total_count=self._get_attribute(combined_status,'total_count') |
73 | 104 |
|
74 | | -#: List of :class:`Status <github3.repos.status.Status>` |
75 | | -#: objects. |
76 | | -statuses=self._get_attribute(combined_status,'statuses', []) |
77 | | -self.statuses= [Status(s,self)forsinstatuses] |
| 105 | +classCombinedStatus(GitHubCore): |
| 106 | +"""A representation of the combined statuses in a repository. |
| 107 | +
|
| 108 | + See also: http://developer.github.com/v3/repos/statuses/ |
| 109 | +
|
| 110 | + This object has the following attributes: |
| 111 | +
|
| 112 | + .. attribute:: commit_url |
| 113 | +
|
| 114 | + The URL of the commit this combined status is present on. |
| 115 | +
|
| 116 | + .. attribute:: repository |
| 117 | +
|
| 118 | + A :class:`~gitub3.repos.repo.ShortRepository` representing the |
| 119 | + repository on which this combined status exists. |
| 120 | +
|
| 121 | + .. attribute:: sha |
78 | 122 |
|
| 123 | + The SHA1 of the commit this status exists on. |
| 124 | +
|
| 125 | + .. attribute:: state |
| 126 | +
|
| 127 | + The state of the combined status, e.g., ``'success'``, ``'pending'``, |
| 128 | + ``'failure'``. |
| 129 | +
|
| 130 | + .. attribute:: statuses |
| 131 | +
|
| 132 | + The list of :class:`~github3.repos.status.ShortStatus` objects |
| 133 | + representing the individual statuses that is combined in this object. |
| 134 | +
|
| 135 | + .. attribute:: total_count |
| 136 | +
|
| 137 | + The total number of sub-statuses. |
| 138 | + """ |
| 139 | + |
| 140 | +def_update_attributes(self,combined_status): |
79 | 141 | from .importrepo |
80 | | -#: Repository the combined status belongs too. |
81 | | -self.repository=self._class_attribute( |
82 | | -combined_status,'repository',repo.ShortRepository,self |
| 142 | +self._api=combined_status['url'] |
| 143 | +self.commit_url=combined_status['commit_url'] |
| 144 | +self.repository=repo.ShortRepository( |
| 145 | +combined_status['repository'],self, |
83 | 146 | ) |
84 | | - |
85 | | -#: commit URL |
86 | | -self.commit_url=self._get_attribute(combined_status,'commit_url') |
| 147 | +self.sha=self._get_attribute(combined_status,'sha') |
| 148 | +self.state=self._get_attribute(combined_status,'state') |
| 149 | +statuses=self._get_attribute(combined_status,'statuses', []) |
| 150 | +self.statuses= [ShortStatus(s,self)forsinstatuses] |
| 151 | +self.total_count=self._get_attribute(combined_status,'total_count') |
87 | 152 |
|
88 | 153 | def_repr(self): |
89 | 154 | f='<CombinedStatus [{s.state}:{s.total_count} sub-statuses]>' |
|