forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.py
More file actions
157 lines (100 loc) · 4.3 KB
/
Copy pathstatus.py
File metadata and controls
157 lines (100 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# -*- coding: utf-8 -*-
"""This module contains the Status object for GitHub's commit status API."""
from __future__ import unicode_literals
from .. import models
from .. import users
from ..models import GitHubCore
class _Status(models.GitHubCore):
"""Representation of a status on a repository."""
class_name = "_Status"
def _update_attributes(self, status):
self._api = status["url"]
self.context = status["context"]
self.created_at = self._strptime(status["created_at"])
self.description = status["description"]
self.id = status["id"]
self.state = status["state"]
self.target_url = status["target_url"]
self.updated_at = self._strptime(status["updated_at"])
def _repr(self):
return "<{s.class_name} [{s.id}:{s.state}]>".format(s=self)
class Status(_Status):
"""Representation of a full status on a repository.
See also: http://developer.github.com/v3/repos/statuses/
This object has the same attributes as a
:class:`~github3.repos.status.ShortStatus` as well as the following
attributes:
.. attribute:: creator
A :class:`~github3.users.ShortUser` representing the user who created
this status.
"""
class_name = "Status"
def _update_attributes(self, status):
super(Status, self)._update_attributes(status)
self.creator = users.ShortUser(status["creator"], self)
class ShortStatus(_Status):
"""Representation of a short status on a repository.
.. versionadded:: 1.0.0
This is the representation found in a
:class:`~github3.repos.status.CombinedStatus` object.
See also: http://developer.github.com/v3/repos/statuses/
This object has the following attributes:
.. attribute:: context
This is a string that explains the context of this status object.
For example, ``'continuous-integration/travis-ci/pr'``.
.. attribute:: created_at
A :class:`~datetime.datetime` object representing the date and time
when this status was created.
.. attribute:: creator
A :class:`~github3.users.ShortUser` representing the user who created
this status.
.. attribute:: description
A short description of the status.
.. attribute:: id
The unique identifier of this status object.
.. attribute:: state
The state of this status, e.g., ``'success'``, ``'pending'``,
``'failure'``.
.. attribute:: target_url
The URL to retrieve more information about this status.
.. attribute:: updated_at
A :class:`~datetime.datetime` object representing the date and time
when this status was most recently updated.
"""
class_name = "ShortStatus"
_refresh_to = Status
class CombinedStatus(GitHubCore):
"""A representation of the combined statuses in a repository.
See also: http://developer.github.com/v3/repos/statuses/
This object has the following attributes:
.. attribute:: commit_url
The URL of the commit this combined status is present on.
.. attribute:: repository
A :class:`~gitub3.repos.repo.ShortRepository` representing the
repository on which this combined status exists.
.. attribute:: sha
The SHA1 of the commit this status exists on.
.. attribute:: state
The state of the combined status, e.g., ``'success'``, ``'pending'``,
``'failure'``.
.. attribute:: statuses
The list of :class:`~github3.repos.status.ShortStatus` objects
representing the individual statuses that is combined in this object.
.. attribute:: total_count
The total number of sub-statuses.
"""
def _update_attributes(self, combined_status):
from . import repo
self._api = combined_status["url"]
self.commit_url = combined_status["commit_url"]
self.repository = repo.ShortRepository(
combined_status["repository"], self
)
self.sha = combined_status["sha"]
self.state = combined_status["state"]
statuses = combined_status["statuses"]
self.statuses = [ShortStatus(s, self) for s in statuses]
self.total_count = combined_status["total_count"]
def _repr(self):
f = "<CombinedStatus [{s.state}:{s.total_count} sub-statuses]>"
return f.format(s=self)