8000 Add creation of a Project via Organization · pythonthings/github3.py@d2e06b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit d2e06b0

Browse files
rco-abletonsigmavirus24
authored andcommitted
Add creation of a Project via Organization
1 parent 690dc55 commit d2e06b0

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

github3/orgs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .decorators import requires_auth
1919
from .events import Event
2020
from .models import BaseAccount, GitHubCore
21+
from .projects import Project
2122
from .repos import Repository
2223

2324

@@ -346,6 +347,22 @@ def add_repository(self, repository, team_id):
346347
url = self._build_url('teams', str(team_id), 'repos', str(repository))
347348
return self._boolean(self._put(url), 204, 404)
348349

350+
@requires_auth
351+
def create_project(self, name, body=''):
352+
"""Create a project for this organization.
353+
354+
If the client is authenticated and a member of the organization, this
355+
will create a new project in the organization.
356+
357+
:param str name: (required), name of the project
358+
:param str body: (optional), the body of the project
359+
"""
360+
url = self._build_url('projects', base_url=self._api)
361+
data = {'name': name, 'body': body}
362+
json = self._json(self._post(
363+
url, data, headers=Project.CUSTOM_HEADERS), 201)
364+
return self._instance_or_null(Project, json)
365+
349366
@requires_auth
350367
def create_repository(self, name, description='', homepage='',
351368
private=False, has_issues=True, has_wiki=True,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"recorded_with": "betamax/0.8.0", "http_interactions": [{"request": {"uri": "https://api.github.com/orgs/github3py", "headers": {"Connection": "keep-alive", "Accept": "application/vnd.github.v3.full+json", "Accept-Encoding": "gzip, deflate", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "token <AUTH_TOKEN>", "User-Agent": "github3.py/1.0.0a4"}, "body": {"encoding": "utf-8", "string": ""}, "method": "GET"}, "response": {"headers": {"X-Frame-Options": "deny", "X-RateLimit-Reset": "1487675942", "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", "Content-Security-Policy": "default-src 'none'", "X-XSS-Protection": "1; mode=block", "Date": "Tue, 21 Feb 2017 10:25:04 GMT", "Last-Modified": "Sun, 05 Feb 2017 09:48:33 GMT", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "X-GitHub-Request-Id": "EFB6:7030:78EBCCA:96CA575:58AC157F", "X-RateLimit-Remaining": "4997", "X-Served-By": "13d09b732ebe76f892093130dc088652", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Transfer-Encoding": "chunked", "Content-Type": "application/json; charset=utf-8", "X-GitHub-Media-Type": "github.v3; param=full; format=json", "X-OAuth-Scopes": "repo", "Status": "200 OK", "Server": "GitHub.com", "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", "X-RateLimit-Limit": "5000", "Content-Encoding": "gzip", "ETag": "W/\"c0acecdf6db98116edd63d9ff9a29ea4\"", "X-Content-Type-Options": "nosniff", "Access-Control-Allow-Origin": "*"}, "url": "https://api.github.com/orgs/github3py", "status": {"code": 200, "message": "OK"}, "body": {"encoding": "utf-8", "string": "", "base64_string": "H4sIAPIbrFgC/51Su3LCMBD8F9XGDxlDoib5gzRUaTxnWwhNZEkjyTCE4d9zfgVDKtL5Vrs7t3u+EGWE1IQRIcOhq3J7JhGRDWHZ9oVmxSYinVP4fAjBepYkYGU8UuPatIlxwidLqePW+PIJTTIoUMmPXIfnpKMEtS1vK+6eE0+ay/RxRRvbVUrW5X/c7qVLUzhCAPdoNoB+Muw8d7XRAdMM3l0ytf+Geg0tv90nHlpGkgV9XsDSIFzhMQnTnVIR3rWGII2eZ96CVPMwbTtWz4pfQEiPfbI0InujlDlhlMUktRimQ2jVQ55FMcu/oXYcAm9KCMilaUZXabGi2126ZrRg+eYTOZ1t7jjrnpPRXUpZkbH8teeEs+07+HACtPwecyFqAqjSOoll8jkM7mdOGv3+4jNyS9lI/1V2HgS6Z+m6L1YpqIyDYKbolVQKg5dTf0S4GPb7GPpLqbiVOhbm+C761z5+/xcpwNYv8+H2jnNEvYUaxzzd0nSxy7zd9foDgB/AOYsDAAA="}}, "recorded_at": "2017-02-21T10:25:14"}, {"request": {"uri": "https://api.github.com/orgs/github3py/projects", "headers": {"Connection": "keep-alive", "Accept": "application/vnd.github.inertia-preview+json", "Accept-Encoding": "gzip, deflate", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "token <AUTH_TOKEN>", "Content-Length": "45", "User-Agent": "github3.py/1.0.0a4"}, "body": {"encoding": "utf-8", "string": "{\"name\": \"test-project\", \"body\": \"test body\"}"}, "method": "POST"}, "response": {"headers": {"X-Frame-Options": "deny", "X-RateLimit-Reset": "1487675942", "Content-Type": "application/json; charset=utf-8", "Content-Security-Policy": "default-src 'none'", "X-XSS-Protection": "1; mode=block", "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", "Cache-Control": "private, max-age=60, s-maxage=60", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "X-GitHub-Request-Id": "EFB6:7030:78EBCD9:96CA58A:58AC1580", "X-RateLimit-Remaining": "4996", "X-Served-By": "01d096e6cfe28f8aea352e988c332cd3", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Content-Length": "1242", "Location": "https://api.github.com/projects/400227", "X-GitHub-Media-Type": "github.inertia-preview; format=json", "X-OAuth-Scopes": "repo", "Date": "Tue, 21 Feb 2017 10:25:04 GMT", "Status": "201 Created", "Server": "GitHub.com", "X-Accepted-OAuth-Scopes": "repo", "X-RateLimit-Limit": "5000", "ETag": "\"47924aa0be05b5eb8d5ed9a2a638df22\"", "X-Content-Type-Options": "nosniff", "Access-Control-Allow-Origin": "*"}, "url": "https://api.github.com/orgs/github3py/projects", "status": {"code": 201, "message": "Created"}, "body": {"encoding": "utf-8", "string": "{\"owner_url\":\"https://api.github.com/orgs/github3py\",\"url\":\"https://api.github.com/projects/400227\",\"columns_url\":\"https://api.github.com/projects/400227/columns\",\"id\":400227,\"name\":\"test-project\",\"body\":\"test body\",\"number\":3,\"state\":\"open\",\"creator\":{\"login\":\"rco-ableton\",\"id\":11273197,\"avatar_url\":\"https://avatars3.githubusercontent.com/u/11273197?v=3\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/rco-ableton\",\"html_url\":\"https://github.com/rco-ableton\",\"followers_url\":\"https://api.github.com/users/rco-ableton/followers\",\"following_url\":\"https://api.github.com/users/rco-ableton/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/rco-ableton/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/rco-ableton/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/rco-ableton/subscriptions\",\"organizations_url\":\"https://api.github.com/users/rco-ableton/orgs\",\"repos_url\":\"https://api.github.com/users/rco-ableton/repos\",\"events_url\":\"https://api.github.com/users/rco-ableton/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/rco-ableton/received_events\",\"type\":\"User\",\"site_admin\":false},\"created_at\":\"2017-02-21T10:25:04Z\",\"updated_at\":\"2017-02-21T10:25:04Z\"}"}}, "recorded_at": "2017-02-21T10:25:15"}, {"request": {"uri": "https://api.github.com/projects/400227", "headers": {"Connection": "keep-alive", "Accept": "application/vnd.github.inertia-preview+json", "Accept-Encoding": "gzip, deflate", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "token <AUTH_TOKEN>", "Content-Length": "0", "User-Agent": "github3.py/1.0.0a4"}, "body": {"encoding": "utf-8", "string": ""}, "method": "DELETE"}, "response": {"headers": {"X-Frame-Options": "deny", "X-RateLimit-Reset": "1487675942", "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-GitHub-Media-Type": "github.inertia-preview; format=json", "X-XSS-Protection": "1; mode=block", "X-OAuth-Scopes": "repo", "Status": "204 No Content", "Server": "GitHub.com", "X-Accepted-OAuth-Scopes": "repo", "X-RateLimit-Limit": "5000", "Date": "Tue, 21 Feb 2017 10:25:04 GMT", "Content-Security-Policy": "default-src 'none'", "X-GitHub-Request-Id": "EFB6:7030:78EBCFC:96CA5BF:58AC1580", "Vary": "Accept-Encoding", "X-RateLimit-Remaining": "4995", "X-Served-By": "c6c65e5196703428e7641f7d1e9bc353", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "X-Content-Type-Options": "nosniff", "Access-Control-Allow-Origin": "*"}, "url": "https://api.github.com/projects/400227", "status": {"code": 204, "message": "No Content"}, "body": {"encoding": null, "string": ""}}, "recorded_at": "2017-02-21T10:25:15"}]}

tests/integration/test_orgs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ def test_add_repository(self):
4848
team = self.get_team(o)
4949
assert o.add_repository('github3py/urllib3', team.id) is True
5050

51+
def test_create_project(self):
52+
"""Test the ability to create a project in an organization."""
53+
self.token_login()
54+
cassette_name = self.cassette_name('create_org_project')
55+
with self.recorder.use_cassette(cassette_name, **self.betamax_kwargs):
56+
o = self.get_organization(name='github3py')
57+
r = o.create_project('test-project', body='test body')
58+
assert isinstance(r, github3.projects.Project)
59+
assert r.delete() is True
60+
5161
def test_create_repository(self):
5262
"""Test the ability to create a repository in an organization."""
5363
self.basic_login()

tests/unit/test_orgs.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from github3 import GitHubError
55
from github3.orgs import Organization
6+
from github3.projects import Project
67

78
from . import helper
89

@@ -39,6 +40,19 @@ def test_conceal_member(self):
3940
url_for('public_members/concealed')
4041
)
4142

43+
def test_create_project(self):
44+
"""Show that one can create a project in an organization."""
45+
self.instance.create_project('test-project', body='project body')
46+
47+
self.post_called_with(
48+
url_for('projects'),
49+
data={
50+
'name': 'test-project',
51+
'body': 'project body'
52+
},
53+
headers=Project.CUSTOM_HEADERS
54+
)
55+
4256
def test_create_repository(self):
4357
"""Show that one can create a repository in an organization."""
4458
self.instance.create_repository('repo-name', 'description', team_id=1)
@@ -173,6 +187,11 @@ def test_conceal_member(self):
173187
with pytest.raises(GitHubError):
174188
self.instance.conceal_member('user')
175189

190+
def test_create_project(self):
191+
"""Show that one must be authenticated to create a project."""
192+
with pytest.raises(GitHubError):
193+
self.instance.create_project('name', 'body')
194+
176195
def test_create_repository(self):
177196
"""Show that one must be authenticated to create a repo for an org."""
178197
with pytest.raises(GitHubError):

0 commit comments

Comments
 (0)
0