forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel.py
More file actions
118 lines (84 loc) · 2.92 KB
/
label.py
File metadata and controls
118 lines (84 loc) · 2.92 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
# -*- coding: utf-8 -*-
"""Module containing the logic for labels."""
from __future__ import unicode_literals
from json import dumps
from ..decorators import requires_auth
from ..models import GitHubCore
class _Label(GitHubCore):
SYMMETRA_PREVIEW_HEADERS = {
"Accept": "application/vnd.github.symmetra-preview+json"
}
def _update_attributes(self, label):
self._api = label["url"]
self.color = label["color"]
self.name = label["name"]
self._uniq = self._api
def _repr(self):
return "<{0.class_name} [{0.name}]>".format(self)
def __str__(self):
return self.name
@requires_auth
def delete(self):
"""Delete this label.
:returns:
True if successfully deleted, False otherwise
:rtype:
bool
"""
return self._boolean(self._delete(self._api), 204, 404)
@requires_auth
def update(self, name, color, description=None):
"""Update this label.
:param str name:
(required), new name of the label
:param str color:
(required), color code, e.g., 626262, no leading '#'
:param str description:
(optional), new description of the label
:returns:
True if successfully updated, False otherwise
:rtype:
bool
"""
json = None
if name and color:
if color[0] == "#":
color = color[1:]
data = {"name": name, "color": color}
if description is not None:
data["description"] = description
resp = self._patch(
self._api,
data=dumps(data),
headers=self.SYMMETRA_PREVIEW_HEADERS,
)
json = self._json(resp, 200)
if json:
self._update_attributes(json)
return True
return False
class ShortLabel(_Label):
"""A representation of a label object defined on a repository.
See also: http://developer.github.com/v3/issues/labels/
This object has the following attributes::
.. attribute:: color
The hexadecimeal representation of the background color of this label.
.. attribute:: name
The name (display label) for this label.
"""
class_name = "ShortLabel"
class Label(_Label):
"""A representation of a label object defined on a repository.
See also: http://developer.github.com/v3/issues/labels/
This object has the following attributes::
.. attribute:: color
The hexadecimeal representation of the background color of this label.
.. attribute:: desciption
The description for this label.
.. attribute:: name
The name (display label) for this label.
"""
class_name = "Label"
def _update_attributes(self, label):
super(Label, self)._update_attributes(label)
self.description = label["description"]