Skip to content

Commit 4b8eed9

Browse files
committed
🚧 Added support for organizations in git create
* added matching tests * updated name for git hub create cassettes Signed-off-by: Guyzmo <[email protected]>
1 parent 12f7148 commit 4b8eed9

File tree

5 files changed

+424
-4
lines changed

5 files changed

+424
-4
lines changed

git_repo/services/ext/github.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ def connect(self):
3333
'Check your configuration and try again.') from err
3434

3535
def create(self, user, repo, add=False):
36-
if user != self.username:
37-
raise NotImplementedError("Project creation supported for authentified user only!")
3836
try:
39-
self.gh.create_repo(repo)
37+
if user != self.username:
38+
org = self.gh.organization(user)
39+
if org:
40+
org.create_repo(repo)
41+
else:
42+
raise ResourceNotFoundError("Namespace {} neither an organization or current user.".format(user))
43+
else:
44+
self.gh.create_repo(repo)
4045
except github3.models.GitHubError as err:
4146
if err.code == 422 or err.message == 'name already exists on this account':
4247
raise ResourceExistsError("Project already exists.") from err
File renamed without changes.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
{
2+
"http_interactions": [
3+
{
4+
"recorded_at": "2016-10-16T00:15:54",
5+
"request": {
6+
"body": {
7+
"encoding": "utf-8",
8+
"string": ""
9+
},
10+
"headers": {
11+
"Accept": "application/vnd.github.v3.full+json",
12+
"Accept-Charset": "utf-8",
13+
"Accept-Encoding": "identity",
14+
"Authorization": "token <PRIVATE_KEY_GITHUB>",
15+
"Connection": "keep-alive",
16+
"Content-Type": "application/json",
17+
"User-Agent": "github3.py/0.9.5"
18+
},
19+
"method": "GET",
20+
"uri": "https://api.github.com/user"
21+
},
22+
"response": {
23+
"body": {
24+
"encoding": "utf-8",
25+
"string": "{\"login\":\"<GITLAB_NAMESPACE>\",\"id\":254441,\"avatar_url\":\"https://avatars.githubusercontent.com/u/254441?v=3\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>\",\"html_url\":\"https://github.com/<GITLAB_NAMESPACE>\",\"followers_url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>/followers\",\"following_url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>/subscriptions\",\"organizations_url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>/orgs\",\"repos_url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>/repos\",\"events_url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/<GITLAB_NAMESPACE>/received_events\",\"type\":\"User\",\"site_admin\":false,\"name\":\"<GITLAB_NAMESPACE>\",\"company\":null,\"blog\":\"http://<GITLAB_NAMESPACE>.got.nothing.to/blog/\",\"location\":\"Paris\",\"email\":null,\"hireable\":true,\"bio\":null,\"public_repos\":87,\"public_gists\":17,\"followers\":54,\"following\":15,\"created_at\":\"2010-04-27T14:04:09Z\",\"updated_at\":\"2016-09-03T19:19:47Z\"}"
26+
},
27+
"headers": {
28+
"Access-Control-Allow-Origin": "*",
29+
"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",
30+
"Cache-Control": "private, max-age=60, s-maxage=60",
31+
"Content-Length": "1118",
32+
"Content-Security-Policy": "default-src 'none'",
33+
"Content-Type": "application/json; charset=utf-8",
34+
"Date": "Sun, 16 Oct 2016 00:15:54 GMT",
35+
"ETag": "\"552dda7fe01396d75e16d9003f4fd8d7\"",
36+
"Last-Modified": "Sat, 03 Sep 2016 19:19:47 GMT",
37+
"Server": "GitHub.com",
38+
"Status": "200 OK",
39+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
40+
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
41+
"X-Accepted-OAuth-Scopes": "",
42+
"X-Content-Type-Options": "nosniff",
43+
"X-Frame-Options": "deny",
44+
"X-GitHub-Media-Type": "github.v3; param=full; format=json",
45+
"X-GitHub-Request-Id": "4EC11365:1598:D0AB657:5802C6B9",
46+
"X-OAuth-Scopes": "repo, delete_repo, gist",
47+
"X-RateLimit-Limit": "5000",
48+
"X-RateLimit-Remaining": "4984",
49+
"X-RateLimit-Reset": "1476580399",
50+
"X-Served-By": "7efb7ae49588ef0269c6a1c1bd3721d9",
51+
"X-XSS-Protection": "1; mode=block"
52+
},
53+
"status": {
54+
"code": 200,
55+
"message": "OK"
56+
},
57+
"url": "https://api.github.com/user"
58+
}
59+
},
60+
{
61+
"recorded_at": "2016-10-16T00:15:54",
62+
"request": {
63+
"body": {
64+
"encoding": "utf-8",
65+
"string": ""
66+
},
67+
"headers": {
68+
"Accept": "application/vnd.github.v3.full+json",
69+
"Accept-Charset": "utf-8",
70+
"Accept-Encoding": "identity",
71+
"Authorization": "token <PRIVATE_KEY_GITHUB>",
72+
"Connection": "keep-alive",
73+
"Content-Type": "application/json",
74+
"User-Agent": "github3.py/0.9.5"
75+
},
76+
"method": "GET",
77+
"uri": "https://api.github.com/orgs/test-git-repo"
78+
},
79+
"response": {
80+
"body": {
81+
"encoding": "utf-8",
82+
"string": "{\"login\":\"test-git-repo\",\"id\":22862172,\"url\":\"https://api.github.com/orgs/test-git-repo\",\"repos_url\":\"https://api.github.com/orgs/test-git-repo/repos\",\"events_url\":\"https://api.github.com/orgs/test-git-repo/events\",\"hooks_url\":\"https://api.github.com/orgs/test-git-repo/hooks\",\"issues_url\":\"https://api.github.com/orgs/test-git-repo/issues\",\"members_url\":\"https://api.github.com/orgs/test-git-repo/members{/member}\",\"public_members_url\":\"https://api.github.com/orgs/test-git-repo/public_members{/member}\",\"avatar_url\":\"https://avatars.githubusercontent.com/u/22862172?v=3\",\"description\":null,\"public_repos\":2,\"public_gists\":0,\"followers\":0,\"following\":0,\"html_url\":\"https://github.com/test-git-repo\",\"created_at\":\"2016-10-16T00:09:22Z\",\"updated_at\":\"2016-10-16T00:09:22Z\",\"type\":\"Organization\",\"total_private_repos\":0,\"owned_private_repos\":0,\"private_gists\":0,\"disk_usage\":0,\"collaborators\":0,\"billing_email\":\"<GITLAB_NAMESPACE>[email protected]\",\"plan\":{\"name\":\"free\",\"space\":976562499,\"private_repos\":0,\"filled_seats\":1,\"seats\":0}}"
83+
},
84+
"headers": {
85+
"Access-Control-Allow-Origin": "*",
86+
"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",
87+
"Cache-Control": "private, max-age=60, s-maxage=60",
88+
"Content-Length": "1042",
89+
"Content-Security-Policy": "default-src 'none'",
90+
"Content-Type": "application/json; charset=utf-8",
91+
"Date": "Sun, 16 Oct 2016 00:15:54 GMT",
92+
"ETag": "\"5fecacb8e75f216471110d336947403d\"",
93+
"Last-Modified": "Sun, 16 Oct 2016 00:09:22 GMT",
94+
"Server": "GitHub.com",
95+
"Status": "200 OK",
96+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
97+
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
98+
"X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org",
99+
"X-Content-Type-Options": "nosniff",
100+
"X-Frame-Options": "deny",
101+
"X-GitHub-Media-Type": "github.v3; param=full; format=json",
102+
"X-GitHub-Request-Id": "4EC11365:1598:D0AB666:5802C6BA",
103+
"X-OAuth-Scopes": "repo, delete_repo, gist",
104+
"X-RateLimit-Limit": "5000",
105+
"X-RateLimit-Remaining": "4983",
106+
"X-RateLimit-Reset": "1476580399",
107+
"X-Served-By": "2d7a5e35115884240089368322196939",
108+
"X-XSS-Protection": "1; mode=block"
109+
},
110+
"status": {
111+
"code": 200,
112+
"message": "OK"
113+
},
114+
"url": "https://api.github.com/orgs/test-git-repo"
115+
}
116+
},
117+
{
118+
"recorded_at": "2016-10-16T00:15:54",
119+
"request": {
120+
"body": {
121+
"encoding": "utf-8",
122+
"string": "{\"name\": \"git-repo\", \"homepage\": \"\", \"private\": false, \"has_issues\": true, \"auto_init\": false, \"has_wiki\": true, \"has_downloads\": true, \"gitignore_template\": \"\", \"description\": \"\"}"
123+
},
124+
"headers": {
125+
"Accept": "application/vnd.github.v3.full+json",
126+
"Accept-Charset": "utf-8",
127+
"Accept-Encoding": "identity",
128+
"Authorization": "token <PRIVATE_KEY_GITHUB>",
129+
"Connection": "keep-alive",
130+
"Content-Length": "180",
131+
"Content-Type": "application/json",
132+
"User-Agent": "github3.py/0.9.5"
133+
},
134+
"method": "POST",
135+
"uri": "https://api.github.com/orgs/test-git-repo/repos"
136+
},
137+
"response": {
138+
"body": {
139+
"encoding": "utf-8",
140+
"string": "{\"message\":\"Validation Failed\",\"errors\":[{\"resource\":\"Repository\",\"code\":\"custom\",\"field\":\"name\",\"message\":\"name already exists on this account\"}],\"documentation_url\":\"https://developer.github.com/v3/repos/#create\"}"
141+
},
142+
"headers": {
143+
"Access-Control-Allow-Origin": "*",
144+
"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",
145+
"Content-Length": "215",
146+
"Content-Security-Policy": "default-src 'none'",
147+
"Content-Type": "application/json; charset=utf-8",
148+
"Date": "Sun, 16 Oct 2016 00:15:54 GMT",
149+
"Server": "GitHub.com",
150+
"Status": "422 Unprocessable Entity",
151+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
152+
"X-Accepted-OAuth-Scopes": "public_repo, repo",
153+
"X-Content-Type-Options": "nosniff",
154+
"X-Frame-Options": "deny",
155+
"X-GitHub-Media-Type": "github.v3; param=full; format=json",
156+
"X-GitHub-Request-Id": "4EC11365:1598:D0AB67F:5802C6BA",
157+
"X-OAuth-Scopes": "repo, delete_repo, gist",
158+
"X-RateLimit-Limit": "5000",
159+
"X-RateLimit-Remaining": "4982",
160+
"X-RateLimit-Reset": "1476580399",
161+
"X-XSS-Protection": "1; mode=block"
162+
},
163+
"status": {
164+
"code": 422,
165+
"message": "Unprocessable Entity"
166+
},
167+
"url": "https://api.github.com/orgs/test-git-repo/repos"
168+
}
169+
}
170+
],
171+
"recorded_with": "betamax/0.5.1"
172+
}

0 commit comments

Comments
 (0)