forked from ask/python-github2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissues.py
More file actions
176 lines (136 loc) · 6.53 KB
/
issues.py
File metadata and controls
176 lines (136 loc) · 6.53 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import urllib.request, urllib.parse, urllib.error
from github2.core import GithubCommand, BaseData, Attribute, DateAttribute
class Issue(BaseData):
position = Attribute("The position of this issue in a list.")
number = Attribute("The issue number (unique for project).")
votes = Attribute("Number of votes for this issue.")
body = Attribute("The full description for this issue.")
title = Attribute("Issue title.")
user = Attribute("The username of the user that created this issue.")
state = Attribute("State of this issue. Can be ``open`` or ``closed``.")
labels = Attribute("Labels associated with this issue.")
created_at = DateAttribute("The date this issue was created.")
closed_at = DateAttribute("The date this issue was closed.")
updated_at = DateAttribute("The date when this issue was last updated.")
diff_url = Attribute("URL for diff output associated with this issue.")
patch_url = Attribute("URL for format-patch associated with this issue.")
pull_request_url = Attribute("URL for the issue's related pull request.")
def __repr__(self):
return "<Issue: %s>" % self.title.encode('utf-8')
class Comment(BaseData):
created_at = DateAttribute("The date this comment was created.")
updated_at = DateAttribute("The date when this comment was last updated.")
body = Attribute("The full text of this comment.")
id = Attribute("The comment id.")
user = Attribute("The username of the user that created this comment.")
def __repr__(self):
return "<Comment: %s>" % self.body
class Issues(GithubCommand):
domain = "issues"
def search(self, project, term, state="open"):
"""Get all issues for project that match term with given state.
.. versionadded:: 0.3.0
:param str project: GitHub project
:param str term: term to search issues for
:param str state: can be either ``open`` or ``closed``.
"""
return self.get_values("search", project, state,
urllib.parse.quote_plus(term), filter="issues",
datatype=Issue)
def list(self, project, state="open"):
"""Get all issues for project with given state.
:param str project: GitHub project
:param str state: can be either ``open`` or ``closed``.
"""
return self.get_values("list", project, state, filter="issues",
datatype=Issue)
def list_by_label(self, project, label):
"""Get all issues for project with label.
.. versionadded:: 0.3.0
:param str project: GitHub project
:param str label: a string representing a label (e.g., ``bug``).
"""
return self.get_values("list", project, "label", label, filter="issues",
datatype=Issue)
def list_labels(self, project):
"""Get all labels for project.
.. versionadded:: 0.3.0
:param str project: GitHub project
"""
return self.get_values("labels", project, filter="labels")
def show(self, project, number):
"""Get all the data for issue by issue-number.
:param str project: GitHub project
:param int number: issue number in the Github database
"""
return self.get_value("show", project, str(number),
filter="issue", datatype=Issue)
def open(self, project, title, body):
"""Open up a new issue.
:param str project: GitHub project
:param str title: title for issue
:param str body: body for issue
"""
issue_data = {"title": title, "body": body}
return self.get_value("open", project, post_data=issue_data,
filter="issue", datatype=Issue)
def close(self, project, number):
"""Close an issue
:param str project: GitHub project
:param int number: issue number in the Github database
"""
return self.get_value("close", project, str(number), filter="issue",
datatype=Issue, method="POST")
def reopen(self, project, number):
"""Reopen a closed issue
.. versionadded:: 0.3.0
:param str project: GitHub project
:param int number: issue number in the Github database
"""
return self.get_value("reopen", project, str(number), filter="issue",
datatype=Issue, method="POST")
def edit(self, project, number, title, body):
"""Edit an existing issue
.. versionadded:: 0.3.0
:param str project: GitHub project
:param int number: issue number in the Github database
:param str title: title for issue
:param str body: body for issue
"""
issue_data = {"title": title, "body": body}
return self.get_value("edit", project, str(number),
post_data=issue_data, filter="issue",
datatype=Issue)
def add_label(self, project, number, label):
"""Add a label to an issue
:param str project: GitHub project
:param int number: issue number in the Github database
:param str label: label to attach to issue
"""
return self.make_request("label/add", project, label, str(number),
filter="labels", method="POST")
def remove_label(self, project, number, label):
"""Remove an existing label from an issue
:param str project: GitHub project
:param int number: issue number in the Github database
:param str label: label to remove from issue
"""
return self.make_request("label/remove", project, label, str(number),
filter="labels", method="POST")
def comment(self, project, number, comment):
"""Comment on an issue.
:param str project: GitHub project
:param int number: issue number in the Github database
:param str comment: comment to attach to issue
"""
comment_data = {'comment': comment}
return self.make_request("comment", project, str(number),
post_data=comment_data,
filter='comment')
def comments(self, project, number):
"""View comments on an issue.
:param str project: GitHub project
:param int number: issue number in the Github database
"""
return self.get_values("comments", project, str(number),
filter="comments", datatype=Comment)