8000 Support for Project Columns · pythonthings/github3.py@a48abb8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a48abb8

Browse files
rco-abletonsigmavirus24
authored andcommitted
Support for Project Columns
1 parent 5623770 commit a48abb8

10 files changed

+312
-0
lines changed

github3/projects.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,53 @@ def _update_attributes(self, project):
5454
def _repr(self):
5555
return '<Project [#{0}]>'.format(self.id)
5656

57+
def column(self, id):
58+
"""Get a project column with the given ID.
59+
60+
:param int id: (required), the column ID
61+
:returns: :class:`ProjectColumn <github3.projects.ProjectColumn>`
62+
or None
63+
"""
64+
url = self._build_url(
65+
'projects', 'columns', str(id), base_url=self._github_url)
66+
json = self._json(self._get(url, headers=Project.CUSTOM_HEADERS), 200)
67+
return self._instance_or_null(ProjectColumn, json)
68+
69+
def columns(self, number=-1, etag=None):
70+
"""Iterate over the columns in this project.
71+
72+
:param int number: (optional), number of columns to return. Default:
73+
-1 returns all available columns.
74+
:param str etag: (optional), ETag from a previous request to the same
75+
endpoint
76+
:returns: generator of
77+
:class:`ProjectColumn <github3.project.ProjectColumn>`
78+
"""
79+
url = self._build_url(
80+
'projects', str(self.id), 'columns', base_url=self._github_url)
81+
return self._iter(
82+
int(number),
83+
url,
84+
ProjectColumn,
85+
headers=Project.CUSTOM_HEADERS,
86+
etag=etag
87+
)
88+
89+
@requires_auth
90+
def create_column(self, name):
91+
"""Create a column in this project.
92+
93+
:param str name: (required), name of the column
94+
:returns: :class:`ProjectColumn <github3.projects.ProjectColumn>`
95+
or none
96+
"""
97+
url = self._build_url('columns', base_url=self._api)
98+
json = None
99+
if name:
100+
json = self._json(self._post(
101+
url, data={'name': name}, headers=Project.CUSTOM_HEADERS), 201)
102+
return self._instance_or_null(ProjectColumn, json)
103+
57104
@requires_auth
58105
def delete(self):
59106
"""Delete this project.
@@ -83,3 +130,86 @@ def update(self, name=None, body=None):
83130
self._update_attributes(json)
84131
return True
85132
return False
133+
134+
135+
class ProjectColumn(models.GitHubCore):
136+
"""The :class:`ProjectColumn <ProjectColumn>` object.
137+
138+
See http://developer.github.com/v3/projects/columns/
139+
"""
140+
141+
def _update_attributes(self, project_column):
142+
#: datetime object representing the last time the object was created
143+
self.created_at = self._strptime_attribute(
144+
project_column, 'created_at')
145+
146+
#: The ID of this column
147+
self.id = self._get_attribute(project_column, 'id')
148+
149+
#: The name of this column
150+
self.name = self._get_attribute(project_column, 'name')
151+
152+
#: The URL of this column's project
153+
self.project_url = self._get_attribute(project_column, 'project_url')
154+
155+
#: datetime object representing the last time the object was changed
156+
self.updated_at = self._strptime_attribute(
157+
project_column, 'updated_at')
158+
159+
def _repr(self):
160+
return '<ProjectColumn [#{0}]>'.format(self.id)
161+
162+
@requires_auth
163+
def delete(self):
164+
"""Delete this column.
165+
166+
:returns: bool
167+
"""
168+
url = self._build_url(
169+
'projects/columns', self.id, base_url=self._github_url)
170+
return self._boolean(self._delete(
171+
url, headers=Project.CUSTOM_HEADERS), 204, 404)
172+
173+
@requires_auth
174+
def move(self, position):
175+
"""Move this column.
176+
177+
:param str position: (required), can be one of `first`, `last`,
178+
or `after:<column-id>`, where `<column-id>` is the id value
179+
of a column in the same project.
180+
:returns: bool
181+
"""
182+
if not position:
183+
return False
184+
185+
url = self._build_url(
186+
'projects/columns',
187+
self.id,
188+
'moves',
189+
base_url=self._github_url
190+
)
191+
data = {'position': position}
192+
return self._boolean(self._post(
193+
url, data=data, headers=Project.CUSTOM_HEADERS), 201, 404)
194+
195+
@requires_auth
196+
def update(self, name=None):
197+
"""Update this column.
198+
199+
:param str name: (optional), name of the column
200+
:returns: bool
201+
"""
202+
data = {'name': name}
203+
json = None
204+
self._remove_none(data)
205+
206+
if data:
207+
url = self._build_url(
208+
'projects/columns', self.id, base_url=self._github_url)
209+
json = self._json(self._patch(
210+
url, data=dumps(data), headers=Project.CUSTOM_HEADERS), 200)
211+
212+
if json:
213+
self._update_attributes(json)
214+
return True
215+
return False
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"method": "GET", "body": {"encoding": "utf-8", "string": ""}, "uri": "https://api.github.com/repos/sigmavirus24/github3.py", "headers": {"Connection": "keep-alive", "Accept-Charset": "utf-8", "User-Agent": "github3.py/1.0.0a4", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.drax-preview+json", "Authorization": "token <AUTH_TOKEN>", "Content-Type": "application/json"}}, "response": {"status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py", "body": {"encoding": "utf-8", "string": "", "base64_string": "H4sIAAAAAAAAA+2YTW/jNhCG/4qhax3Tjrtx10CxLdB7L3vqxaAl2iJCkQJJ2U2E/Pe+I+rLDnblNffQQ4AgsRXy4avhDDkzdSKzZLtZ/7b6vFlv5onmhUi2iRfOW1GaZJ4cKqV27eM/90p4o/8Sp6/GKMdGw8xZC5ts60SZo9RAXI0FiVZarZ+e8LOaJ/zEPbe7yioMzr0v3Zax8NAtjtLn1b5ywqZGe6H9IjUFq1g3/cvp9zWIR9tSCJ3gwRWtlC0pTAfOsfe6cl+oKx1h/WbW+/EHo5Q5g3Ut/oblWD+ZTNuApD7eD8LkmhmfC1gSr/dGRpHO3yWtmVgz+rOTGaEcdsiK7B557VSII8d4qxm5U8Os9i61svTS6LtkXgAANPbItXzldwMBcOCQwLsENRMBECc46l2EMLNmpZUnnr6QmaxIhTzB9vdTrxCA+peSovvvkcVoR6QXO54VFLYHrpx4myeNEo/B3lZijvj8gRAZHwuZ6DebzoRZqXgqZgdjZ5brzBQz8W8prCzIcjM8mTkzM3oBVRjz3OqZiOvG/tdxOhZBqIl9+T4DUQsCRD2LlzgQAWqG322EpTgC+N5Y7s3UeTIh8YJUs/FX8icveBEnvSGAlBsTac2GAJJ0rhI3OfjEuzcgx7ow0lWxD2fhLcEzwQ4IqOXOyaMWIs6KPaVm3YG9RyikeSS3g9QsfGr2nB/jxBIAnL0y+zgQ7lPWUGrmch5uKb+L1kdYglxQrTjEiyVIT0UqFLk7jVCi9Ezcjx4OEKe0g7C6tari+ljxYyS2p2Dv6R4/8tfJbGciigYMmJTTWbmvfsKZN4BIa0gtEPuRZh04A7VJWL6fCU3ZYJT5NFYoCjmVL0wgW8aF//8MLvnrNZu+Tyc4NwgmSM2GQzpcAy0+ysLtPdApHS/S1hFxjtFBWP1LyX1O5xjWKrkVUbJbBqv3HMnXYrGoc8GbBLwQNjaYAwIsbtMcGWWU0rqDICEquG/S+gMJzZDmK8OzOPv2FBDDXkapDYixF5QoZuMkNoQxspAKxbLRkWfugBnDtfHyINNbapuJwLsg1V+c1KmYc6Xm8F4vUwl/Ri1JW4l8VEQaKSDwIugmhGJGCbh2nOWtCJCaheI0E6UyL/FH0ohD8WwF6p5sxz3qlcfl6ulhtXpYffq6+nW7/Lz9tPwHY6oymxxTVi4fYTYPy8cG87hdb7arDWFwyLbujU9ofny76dAXM9TOwEzn8mHmH8O87bcaNO28VMFPr0LqB1Y9Xd9/N8yF2twUokRSkmw1gofqzVd8RgtolFukptKw+HKenLlHMowbfHjU5SMdIOduF2K7r0/xZDg8uqIVD8/yWY4HkQ7Xl5WhMBwWKqS1pu1JBa2mFLpdqxME4aEcJLWj/zev1KlvXiUTB14pvwsZOfyp4M6jS4byWtgCb0AtEOqZtcV3qLXJczrJdNqEz6jJlUyFdr0Zx32Pj8bbyBWprnrfD/hovH003t41if5/jTct/BnNptHpN65q2qNq/fYf908+1LgXAAA="}, "headers": {"X-Frame-Options": "deny", "Transfer-Encoding": "chunked", "Status": "200 OK", "Last-Modified": "Tue, 15 Nov 2016 14:09:50 GMT", "X-Served-By": "a7f8a126c9ed3f1c4715a34c0ddc7290", "Content-Type": "application/json; charset=utf-8", "X-RateLimit-Remaining": "4952", "Cache-Control": "private, max-age=60, s-maxage=60", "Server": "GitHub.com", "Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "X-OAuth-Scopes": "repo", "X-GitHub-Media-Type": "github.drax-preview; format=json", "X-Accepted-OAuth-Scopes": "repo", "Content-Security-Policy": "default-src 'none'", "Date": "Tue, 21 Feb 2017 15:24:04 GMT", "X-Content-Type-Options": "nosniff", "X-GitHub-Request-Id": "F159:1EBD2:9C38185:C9834B8:58AC5B94", "Access-Control-Allow-Origin": "*", "X-XSS-Protection": "1; mode=block", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "ETag": "W/\"f2528211d57d91b73858bae183c81d71\"", "X-RateLimit-Limit": "5000", "Content-Encoding": "gzip", "X-RateLimit-Reset": "1487693068"}}, "recorded_at": "2017-02-21T15:24:14"}, {"request": {"method": "GET", "body": {"encoding": "utf-8", "string": ""}, "uri": "https://api.github.com/projects/400903", "headers": {"Connection": "keep-alive", "Accept-Charset": "utf-8", "User-Agent": "github3.py/1.0.0a4", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.inertia-preview+json", "Authorization": "token <AUTH_TOKEN>", "Content-Type": "application/json"}}, "response": {"status": {"message": "OK", "code": 200}, "url": "https://api.github.com/projects/400903", "body": {"encoding": "utf-8", "string": "", "base64_string": "H4sIAAAAAAAAA52T0W7bMAxFf2XQc1LZTrOgBoZhQD+hfelLINuso0EWBYl2kRn595GONyzJkCJ5smHxXF1ek6PCDw9x20enSrUjCqnU2gT70Fra9dVDjZ2OEDDpH5UDQv8MwwuiS5ogkZyohbpKh4g/oaakH7PsKVtxeY2u73y6fukZpmeIcduo8qi1UN50wMbFy5eZ4IoKmz1/5TffdxVEVa4XKpEhqcUAXkxEMIR8NCqHrfV8EmtcmmOX8zV5XmxW+dNmocxgyFzkNH1MqzmsPgFLeAJPU269/sN/H75J422cZaQFsXc1OJFL+tTUjjp3ltu/P+qkgXd0Dj9Y43rQF9fovyA7PL5b394nwuCokXYyYtzOQUKwiW62NEGjlsfWNiLDvzNGaG61NWNsSub+ME7DPen1VaqjDWTxs9G8TOwEZjGMrfH2l7lLjOHEGtPW3dreBDEMAw/hzfSRGnWIdjD1XmKJUIMdOOf7FM9wFqR9kC185WmQ1C3B1jSd7N+7cQkO82byjYa4rsjyzTIrlkX+kq/LbF0+rt+Y60PD2/zfmqIoi69v6vAblNIgV9sEAAA="}, "headers": {"X-Frame-Options": "deny", "Transfer-Encoding": "chunked", "Status": "200 OK", "X-Served-By": "d0b3c2c33a23690498aa8e70a435a259", "Content-Type": "application/json; charset=utf-8", "X-RateLimit-Remaining": "4951", "Cache-Control": "private, max-age=60, s-maxage=60", "Server": "GitHub.com", "Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "X-OAuth-Scopes": "repo", "X-GitHub-Media-Type": "github.inertia-preview; format=json", "X-Accepted-OAuth-Scopes": "repo", "Content-Security-Policy": "default-src 'none'", "Date": "Tue, 21 Feb 2017 15:24:04 GMT", "X-Content-Type-Options": "nosniff", "X-GitHub-Request-Id": "F159:1EBD2:9C381B9:C983502:58AC5B94", "Access-Control-Allow-Origin": "*", "X-XSS-Protection": "1; mode=block", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "ETag": "W/\"ae29af6779b3fb4f6658afb37e68bbe2\"", "X-RateLimit-Limit": "5000", "Content-Encoding": "gzip", "X-RateLimit-Reset": "1487693068"}}, "recorded_at": "2017-02-21T15:24:15"}, {"request": {"method": "GET", "body": {"encoding": "utf-8", "string": ""}, "uri": "https://api.github.com/projects/columns/698995", "headers": {"Connection": "keep-alive", "Accept-Charset": "utf-8", "User-Agent": "github3.py/1.0.0a4", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.inertia-preview+json", "Authorization": "token <AUTH_TOKEN>", "Content-Type": "application/json"}}, "response": {"status": {"message": "OK", "code": 200}, "url": "https://api.github.com/projects/columns/698995", "body": {"encoding": "utf-8", "string": "", "base64_string": "H4sIAAAAAAAAA42OuxLCIBBFf8XZOskCERW+w8omg8AYnCQwPCrHfxeNjZVpd8+59z6gxAkkjDmHJBFVcN3N5bFcO+1nDNHfrc4JtZ/KvCQ8iJMQHBr4foZt+p4QQfqqaRVN2ij9duJHrRHOgFxnNLCo2db1K7lj74JoVbZmULneGaHHlrCW0TPlknDJ+0tlSjB/mOcLo9TmOhgBAAA="}, "headers": {"X-Frame-Options": "deny", "Transfer-Encoding": "chunked", "Status": "200 OK", "X-Served-By": "bae57931a6fe678a3dffe9be8e7819c8", "Content-Type": "application/json; charset=utf-8", "X-RateLimit-Remaining": "4950", "Cache-Control": "private, max-age=60, s-maxage=60", "Server": "GitHub.com", "Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "X-OAuth-Scopes": "repo", "X-GitHub-Media-Type": "github.inertia-preview; format=json", "X-Accepted-OAuth-Scopes": "repo", "Content-Security-Policy": "default-src 'none'", "Date": "Tue, 21 Feb 2017 15:24:05 GMT", "X-Content-Type-Options": "nosniff", "X-GitHub-Request-Id": "F159:1EBD2:9C38210:C983563:58AC5B94", "Access-Control-Allow-Origin": "*", "X-XSS-Protection": "1; mode=block", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "ETag": "W/\"d821a5f40c7de0927e4ef3e22aca073b\"", "X-RateLimit-Limit": "5000", "Content-Encoding": "gzip", "X-RateLimit-Reset": "1487693068"}}, "recorded_at": "2017-02-21T15:24:15"}, {"request": {"method": "DELETE", "body": {"encoding": "utf-8", "string": ""}, "uri": "https://api.github.com/projects/columns/698995", "headers": {"Connection": "keep-alive", "Content-Length": "0", "Accept-Charset": "utf-8", "User-Agent": "github3.py/1.0.0a4", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.inertia-preview+json", "Authorization": "token <AUTH_TOKEN>", "Content-Type": "application/json"}}, "response": {"status": {"message": "No Content", "code": 204}, "url": "https://api.github.com/projects/columns/698995", "body": {"encoding": null, "string": ""}, "headers": {"Content-Security-Policy": "default-src 'none'", "X-Frame-Options": "deny", "Date": "Tue, 21 Feb 2017 15:24:05 GMT", "X-Content-Type-Options": "nosniff", "Status": "204 No Content", "Vary": "Accept-Encoding", "X-Served-By": "2c18a09f3ac5e4dd1e004af7c5a94769", "X-GitHub-Request-Id": "F159:1EBD2:9C38255:C9835B4:58AC5B95", "Access-Control-Allow-Origin": "*", "X-XSS-Protection": "1; mode=block", "X-RateLimit-Reset": "1487693068", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "X-RateLimit-Limit": "5000", "Server": "GitHub.com", "Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "X-RateLimit-Remaining": "4949", "X-OAuth-Scopes": "repo", "X-GitHub-Media-Type": "github.inertia-preview; format=json", "X-Accepted-OAuth-Scopes": "repo"}}, "recorded_at": "2017-02-21T15:24:16"}], "recorded_with": "betamax/0.8.0"}

0 commit comments

Comments
 (0)
0