Skip to content

Commit 2dcd901

Browse files
committed
Merge branch requests/github/144 into devel
fixes #144 fixes #142
2 parents 625cb64 + e8dcdd6 commit 2dcd901

File tree

37 files changed

+2136
-7
lines changed

37 files changed

+2136
-7
lines changed

git_repo/repo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ def _guess_repo_slug(self, repository, service, resolve_targets=None):
165165
for url in remote.urls:
166166
if url.endswith('.git'):
167167
url = url[:-4]
168-
if url.find('://') > -1:
169-
# http://, https:// and ssh://
168+
# strip http://, https:// and ssh://
169+
if '://' in url:
170170
*_, user, name = url.split('/')
171171
self.set_repo_slug('/'.join([user, name]))
172172
return
173-
elif url.find('@') > -1 and url.find(':') > -1:
174-
# scp-style URL
173+
# scp-style URL
174+
elif '@' in url and ':' in url:
175175
_, repo_slug = url.split(':')
176176
self.set_repo_slug(repo_slug)
177177
return

git_repo/services/ext/gitbucket.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
log = logging.getLogger('git_repo.gitbucket')
5+
6+
from ..service import register_target
7+
from .github import GithubService
8+
from ...exceptions import ArgumentError
9+
10+
import github3
11+
12+
@register_target('bucket', 'gitbucket')
13+
class GitbucketService(GithubService):
14+
fqdn = "localhost"
15+
port = 8080
16+
17+
def __init__(self, *args, **kwarg):
18+
super(GitbucketService, self).__init__(*args, **kwarg)
19+
20+
@classmethod
21+
def get_auth_token(cls, login, password, prompt=None):
22+
print("Please open the following URL: {}/{}/_application".format(cls.build_url(cls), login))
23+
print("Generate a new token, and paste it at the following prompt.")
24+
return prompt('token> ')
25+
26+
def format_path(self, repository, namespace=None, rw=False):
27+
repo = repository
28+
if namespace:
29+
repo = '{}/{}'.format(namespace, repository)
30+
31+
if not rw and '/' in repo:
32+
return '{}/git/{}.git'.format(self.url_ro, repo)
33+
elif rw and '/' in repo:
34+
if 'ssh://' in self.url_rw:
35+
return '{}/{}.git'.format(self.url_rw, repo)
36+
else:
37+
return '{}:{}.git'.format(self.url_rw, repo)
38+
else:
39+
raise ArgumentError("Cannot tell how to handle this url: `{}/{}`!".format(namespace, repo))
40+
41+
def delete(self, repo, user=None):
42+
raise NotImplementedError("GitBucket doesn't suport this action now.")
43+
44+
def request_create(self, user, repo, from_branch, onto_branch, title=None, description=None, auto_slug=False, edit=None):
45+
raise NotImplementedError("GitBucket doesn't support this action now.")
46+
47+
def gist_list(self, gist=None):
48+
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")
49+
50+
def gist_fetch(self, gist, fname=None):
51+
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")
52+
53+
def gist_clone(self, gist):
54+
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")
55+
56+
def gist_create(self, gist_pathes, description, secret=False):
57+
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")
58+
59+
def gist_delete(self, gist_id):
60+
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")

git_repo/services/ext/github.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@
1313

1414
from datetime import datetime
1515

16+
GITHUB_COM_FQDN = 'github.com'
17+
1618
@register_target('hub', 'github')
1719
class GithubService(RepositoryService):
18-
fqdn = 'github.com'
20+
fqdn = GITHUB_COM_FQDN
1921

2022
def __init__(self, *args, **kwarg):
2123
self.gh = github3.GitHub()
2224
super(GithubService, self).__init__(*args, **kwarg)
2325

2426
def connect(self):
27+
if self.fqdn != GITHUB_COM_FQDN:
28+
# upgrade self.gh from a GitHub object to a GitHubEnterprise object
29+
gh = github3.GitHubEnterprise(RepositoryService.build_url(self))
30+
self.gh._session.base_url = gh._session.base_url
31+
gh._session = self.gh._session
32+
self.gh = gh
33+
# propagate ssl certificate parameter
34+
self.gh._session.verify = self.session_certificate or not self.session_insecure
2535
try:
2636
self.gh.login(token=self._privatekey)
2737
self.username = self.gh.user().login
@@ -284,7 +294,7 @@ def request_fetch(self, user, repo, request, pull=False, force=False):
284294
try:
285295
for remote in self.repository.remotes:
286296
if remote.name == self.name:
287-
local_branch_name = 'requests/github/{}'.format(request)
297+
local_branch_name = 'requests/{}/{}'.format(self.name,request)
288298
self.fetch(
289299
remote,
290300
'pull/{}/head'.format(request),
@@ -302,7 +312,10 @@ def request_fetch(self, user, repo, request, pull=False, force=False):
302312
@classmethod
303313
def get_auth_token(cls, login, password, prompt=None):
304314
import platform
305-
gh = github3.GitHub()
315+
if self.fqdn != GITHUB_COM_FQDN:
316+
gh = github3.GitHubEnterprise()
317+
else:
318+
gh = github3.GitHub()
306319
gh.login(login, password, two_factor_callback=lambda: prompt('2FA code> '))
307320
try:
308321
auth = gh.authorize(login, password,
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{
2+
"http_interactions": [
3+
{
4+
"recorded_at": "2017-04-30T17:42:17",
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_GITBUCKET>",
15+
"Connection": "keep-alive",
16+
"Content-Type": "application/json",
17+
"User-Agent": "github3.py/0.9.5"
18+
},
19+
"method": "GET",
20+
"uri": "http://localhost:8080/api/v3/user"
21+
},
22+
"response": {
23+
"body": {
24+
"encoding": "utf-8",
25+
"string": "{\"login\":\"<GITBUCKET_NAMESPACE>\",\"email\":\"user@localhost\",\"type\":\"User\",\"site_admin\":false,\"created_at\":\"2017-04-30T17:39:36Z\",\"url\":\"http://localhost:8080/api/v3/users/<GITBUCKET_NAMESPACE>\",\"html_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>\",\"avatar_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>/_avatar\"}"
26+
},
27+
"headers": {
28+
"Content-Length": "284",
29+
"Content-Type": "application/json;charset=utf-8",
30+
"Date": "Sun, 30 Apr 2017 17:42:17 GMT",
31+
"Expires": "Thu, 01 Jan 1970 00:00:00 GMT",
32+
"Server": "Jetty(9.3.z-SNAPSHOT)",
33+
"Set-Cookie": "JSESSIONID=odn4jua2ecnf5isyma6dbo21;Path=/;HttpOnly"
34+
},
35+
"status": {
36+
"code": 200,
37+
"message": "OK"
38+
},
39+
"url": "http://localhost:8080/api/v3/user"
40+
}
41+
},
42+
{
43+
"recorded_at": "2017-04-30T17:42:17",
44+
"request": {
45+
"body": {
46+
"encoding": "utf-8",
47+
"string": ""
48+
},
49+
"headers": {
50+
"Accept": "application/vnd.github.v3.full+json",
51+
"Accept-Charset": "utf-8",
52+
"Accept-Encoding": "identity",
53+
"Authorization": "token <PRIVATE_KEY_GITBUCKET>",
54+
"Connection": "keep-alive",
55+
"Content-Type": "application/json",
56+
"Cookie": "JSESSIONID=odn4jua2ecnf5isyma6dbo21",
57+
"User-Agent": "github3.py/0.9.5"
58+
},
59+
"method": "GET",
60+
"uri": "http://localhost:8080/api/v3/repos/root/repo"
61+
},
62+
"response": {
63+
"body": {
64+
"encoding": "utf-8",
65+
"string": "{\"name\":\"repo\",\"full_name\":\"root/repo\",\"description\":\"\",\"watchers\":0,\"forks\":0,\"private\":false,\"default_branch\":\"master\",\"owner\":{\"login\":\"root\",\"email\":\"root@localhost\",\"type\":\"User\",\"site_admin\":true,\"created_at\":\"2017-04-30T17:39:28Z\",\"url\":\"http://localhost:8080/api/v3/users/root\",\"html_url\":\"http://localhost:8080/root\",\"avatar_url\":\"http://localhost:8080/root/_avatar\"},\"forks_count\":0,\"watchers_count\":0,\"url\":\"http://localhost:8080/api/v3/repos/root/repo\",\"http_url\":\"http://localhost:8080/git/root/repo.git\",\"clone_url\":\"http://localhost:8080/git/root/repo.git\",\"html_url\":\"http://localhost:8080/root/repo\"}"
66+
},
67+
"headers": {
68+
"Content-Length": "617",
69+
"Content-Type": "application/json;charset=utf-8",
70+
"Date": "Sun, 30 Apr 2017 17:42:17 GMT",
71+
"Server": "Jetty(9.3.z-SNAPSHOT)"
72+
},
73+
"status": {
74+
"code": 200,
75+
"message": "OK"
76+
},
77+
"url": "http://localhost:8080/api/v3/repos/root/repo"
78+
}
79+
},
80+
{
81+
"recorded_at": "2017-04-30T17:42:24",
82+
"request": {
83+
"body": {
84+
"encoding": "utf-8",
85+
"string": ""
86+
},
87+
"headers": {
88+
"Accept": "application/vnd.github.v3.full+json",
89+
"Accept-Charset": "utf-8",
90+
"Accept-Encoding": "identity",
91+
"Authorization": "token <PRIVATE_KEY_GITBUCKET>",
92+
"Connection": "keep-alive",
93+
"Content-Length": "0",
94+
"Content-Type": "application/json",
95+
"Cookie": "JSESSIONID=odn4jua2ecnf5isyma6dbo21",
96+
"User-Agent": "github3.py/0.9.5"
97+
},
98+
"method": "POST",
99+
"uri": "http://localhost:8080/api/v3/repos/root/repo/forks"
100+
},
101+
"response": {
102+
"body": {
103+
"encoding": null,
104+
"string": ""
105+
},
106+
"headers": {
107+
"Content-Length": "0",
108+
"Date": "Sun, 30 Apr 2017 17:42:17 GMT",
109+
"Server": "Jetty(9.3.z-SNAPSHOT)"
110+
},
111+
"status": {
112+
"code": 404,
113+
"message": "Not Found"
114+
},
115+
"url": "http://localhost:8080/api/v3/repos/root/repo/forks"
116+
}
117+
}
118+
],
119+
"recorded_with": "betamax/0.5.1"
120+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"http_interactions": [
3+
{
4+
"recorded_at": "2017-04-30T17:42:29",
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_GITBUCKET>",
15+
"Connection": "keep-alive",
16+
"Content-Type": "application/json",
17+
"User-Agent": "github3.py/0.9.5"
18+
},
19+
"method": "GET",
20+
"uri": "http://localhost:8080/api/v3/user"
21+
},
22+
"response": {
23+
"body": {
24+
"encoding": "utf-8",
25+
"string": "{\"login\":\"<GITBUCKET_NAMESPACE>\",\"email\":\"user@localhost\",\"type\":\"User\",\"site_admin\":false,\"created_at\":\"2017-04-30T17:39:36Z\",\"url\":\"http://localhost:8080/api/v3/users/<GITBUCKET_NAMESPACE>\",\"html_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>\",\"avatar_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>/_avatar\"}"
26+
},
27+
"headers": {
28+
"Content-Length": "284",
29+
"Content-Type": "application/json;charset=utf-8",
30+
"Date": "Sun, 30 Apr 2017 17:42:29 GMT",
31+
"Expires": "Thu, 01 Jan 1970 00:00:00 GMT",
32+
"Server": "Jetty(9.3.z-SNAPSHOT)",
33+
"Set-Cookie": "JSESSIONID=v1gat922yeob3op8z3zdmrty;Path=/;HttpOnly"
34+
},
35+
"status": {
36+
"code": 200,
37+
"message": "OK"
38+
},
39+
"url": "http://localhost:8080/api/v3/user"
40+
}
41+
},
42+
{
43+
"recorded_at": "2017-04-30T17:42:29",
44+
"request": {
45+
"body": {
46+
"encoding": "utf-8",
47+
"string": "{\"homepage\": \"\", \"private\": false, \"has_wiki\": true, \"has_downloads\": true, \"name\": \"git-repo\", \"description\": \"\", \"gitignore_template\": \"\", \"has_issues\": true, \"auto_init\": false}"
48+
},
49+
"headers": {
50+
"Accept": "application/vnd.github.v3.full+json",
51+
"Accept-Charset": "utf-8",
52+
"Accept-Encoding": "identity",
53+
"Authorization": "token <PRIVATE_KEY_GITBUCKET>",
54+
"Connection": "keep-alive",
55+
"Content-Length": "180",
56+
"Content-Type": "application/json",
57+
"Cookie": "JSESSIONID=v1gat922yeob3op8z3zdmrty",
58+
"User-Agent": "github3.py/0.9.5"
59+
},
60+
"method": "POST",
61+
"uri": "http://localhost:8080/api/v3/user/repos"
62+
},
63+
"response": {
64+
"body": {
65+
"encoding": "utf-8",
66+
"string": "{\"name\":\"git-repo\",\"full_name\":\"<GITBUCKET_NAMESPACE>/git-repo\",\"description\":\"\",\"watchers\":0,\"forks\":0,\"private\":false,\"default_branch\":\"master\",\"owner\":{\"login\":\"<GITBUCKET_NAMESPACE>\",\"email\":\"user@localhost\",\"type\":\"User\",\"site_admin\":false,\"created_at\":\"2017-04-30T17:39:36Z\",\"url\":\"http://localhost:8080/api/v3/users/<GITBUCKET_NAMESPACE>\",\"html_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>\",\"avatar_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>/_avatar\"},\"forks_count\":0,\"watchers_count\":0,\"url\":\"http://localhost:8080/api/v3/repos/<GITBUCKET_NAMESPACE>/git-repo\",\"http_url\":\"http://localhost:8080/git/<GITBUCKET_NAMESPACE>/git-repo.git\",\"clone_url\":\"http://localhost:8080/git/<GITBUCKET_NAMESPACE>/git-repo.git\",\"html_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>/git-repo\"}"
67+
},
68+
"headers": {
69+
"Content-Length": "723",
70+
"Content-Type": "application/json;charset=utf-8",
71+
"Date": "Sun, 30 Apr 2017 17:42:29 GMT",
72+
"Server": "Jetty(9.3.z-SNAPSHOT)"
73+
},
74+
"status": {
75+
"code": 200,
76+
"message": "OK"
77+
},
78+
"url": "http://localhost:8080/api/v3/user/repos"
79+
}
80+
},
81+
{
82+
"recorded_at": "2017-04-30T17:42:30",
83+
"request": {
84+
"body": {
85+
"encoding": "utf-8",
86+
"string": ""
87+
},
88+
"headers": {
89+
"Accept": "application/vnd.github.v3.full+json",
90+
"Accept-Charset": "utf-8",
91+
"Accept-Encoding": "identity",
92+
"Authorization": "token <PRIVATE_KEY_GITBUCKET>",
93+
"Connection": "keep-alive",
94+
"Content-Type": "application/json",
95+
"Cookie": "JSESSIONID=v1gat922yeob3op8z3zdmrty",
96+
"User-Agent": "github3.py/0.9.5"
97+
},
98+
"method": "GET",
99+
"uri": "http://localhost:8080/api/v3/repos/<GITBUCKET_NAMESPACE>/git-repo"
100+
},
101+
"response": {
102+
"body": {
103+
"encoding": "utf-8",
104+
"string": "{\"name\":\"git-repo\",\"full_name\":\"<GITBUCKET_NAMESPACE>/git-repo\",\"description\":\"\",\"watchers\":0,\"forks\":0,\"private\":false,\"default_branch\":\"master\",\"owner\":{\"login\":\"<GITBUCKET_NAMESPACE>\",\"email\":\"user@localhost\",\"type\":\"User\",\"site_admin\":false,\"created_at\":\"2017-04-30T17:39:36Z\",\"url\":\"http://localhost:8080/api/v3/users/<GITBUCKET_NAMESPACE>\",\"html_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>\",\"avatar_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>/_avatar\"},\"forks_count\":0,\"watchers_count\":0,\"url\":\"http://localhost:8080/api/v3/repos/<GITBUCKET_NAMESPACE>/git-repo\",\"http_url\":\"http://localhost:8080/git/<GITBUCKET_NAMESPACE>/git-repo.git\",\"clone_url\":\"http://localhost:8080/git/<GITBUCKET_NAMESPACE>/git-repo.git\",\"html_url\":\"http://localhost:8080/<GITBUCKET_NAMESPACE>/git-repo\"}"
105+
},
106+
"headers": {
107+
"Content-Length": "723",
108+
"Content-Type": "application/json;charset=utf-8",
109+
"Date": "Sun, 30 Apr 2017 17:42:30 GMT",
110+
"Server": "Jetty(9.3.z-SNAPSHOT)"
111+
},
112+
"status": {
113+
"code": 200,
114+
"message": "OK"
115+
},
116+
"url": "http://localhost:8080/api/v3/repos/<GITBUCKET_NAMESPACE>/git-repo"
117+
}
118+
}
119+
],
120+
"recorded_with": "betamax/0.5.1"
121+
}

0 commit comments

Comments
 (0)