Skip to content

Commit dcace1d

Browse files
committed
Update github3.repos.status for consistency
1 parent 7f32e37 commit dcace1d

File tree

1 file changed

+118
-53
lines changed

1 file changed

+118
-53
lines changed

github3/repos/status.py

Lines changed: 118 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,154 @@
11
# -*- 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."""
93
from __future__ import unicode_literals
104

5+
from .. import models
116
from .. import users
127

138
from ..models import GitHubCore
149

1510

16-
class Status(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+
class ShortStatus(_Status):
31+
"""Representation of a short status on a repository.
1832
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.
2037
2138
See also: http://developer.github.com/v3/repos/statuses/
22-
"""
2339
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:
2841
29-
#: datetime object representing the creation of the status object
30-
self.created_at = self._strptime_attribute(status, 'created_at')
42+
.. attribute:: context
3143
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'``.
3646
37-
#: Short description of the Status
38-
self.description = self._get_attribute(status, 'description')
47+
.. attribute:: created_at
3948
40-
#: GitHub ID for the status object
41-
self.id = self._get_attribute(status, 'id')
49+
A :class:`~datetime.datetime` object representing the date and time
50+
when this status was created.
4251
43-
#: State of the status, e.g., 'success', 'pending', 'failed', 'error'
44-
self.state = self._get_attribute(status, 'state')
52+
.. attribute:: creator
4553
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+
this status.
4856
49-
#: datetime object representing the last time the status was updated
50-
self.updated_at = self._strptime_attribute(status, 'updated_at')
57+
.. attribute:: description
5158
52-
def _repr(self):
53-
return '<Status [{s.id}:{s.state}]>'.format(s=self)
59+
A short description of the status.
5460
61+
.. attribute:: id
5562
56-
class CombinedStatus(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'
5881

59-
This represents combined information from the Repo Status API.
82+
83+
class Status(_Status):
84+
"""Representation of a full status on a repository.
6085
6186
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.
6296
"""
6397

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'
6799

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)
70103

71-
#: Total count of sub-statuses
72-
self.total_count = self._get_attribute(combined_status, 'total_count')
73104

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) for s in statuses]
105+
class CombinedStatus(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
78122
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):
79141
from . import repo
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,
83146
)
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) for s in statuses]
151+
self.total_count = self._get_attribute(combined_status, 'total_count')
87152

88153
def _repr(self):
89154
f = '<CombinedStatus [{s.state}:{s.total_count} sub-statuses]>'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy