Skip to content

Commit ec3a83d

Browse files
committed
Change get_auth_token for prompt to user, delete connect, custom format_path.
1 parent e5af447 commit ec3a83d

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

git_repo/services/ext/gitbucket.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from ..service import register_target
77
from .github import GithubService
8+
from ...exceptions import ArgumentError
89

910
import github3
1011

@@ -15,15 +16,11 @@ class GitbucketService(GithubService):
1516
def __init__(self, *args, **kwarg):
1617
super(GitbucketService, self).__init__(*args, **kwarg)
1718

18-
def connect(self):
19-
self.gh = github3.GitHubEnterprise(self.build_url(self))
20-
super(GitbucketService, self).connect()
21-
2219
@classmethod
2320
def get_auth_token(cls, login, password, prompt=None):
24-
print("Please edit _YOUR_ACCESS_TOKEN_ to actual token in ~/.gitconfig or ~/.git/config after.")
25-
print("And add ssh-url = ssh://git@{}:_YOUR_SSH_PORT_".format(cls.fqdn))
26-
return "_YOUR_ACCESS_TOKEN_"
21+
print("Please open the following URL: https://yourgitbucket/youraccount/_application")
22+
print("Generate a new token, and paste it at the following prompt.")
23+
return prompt('token> ')
2724
## this code maybe works when GitBucket supports add access token API.
2825
#print("build_url: ", cls.build_url(cls))
2926
#import platform
@@ -42,10 +39,19 @@ def get_auth_token(cls, login, password, prompt=None):
4239
# raise err
4340

4441
def format_path(self, repository, namespace=None, rw=False):
45-
path = super(GitbucketService, self).format_path(repository, namespace, rw)
46-
if not path.endswith(".git"):
47-
path = "{}.git".format(path)
48-
return path
42+
repo = repository
43+
if namespace:
44+
repo = '{}/{}'.format(namespace, repository)
45+
46+
if not rw and '/' in repo:
47+
return '{}/git/{}.git'.format(self.url_ro, repo)
48+
elif rw and '/' in repo:
49+
if 'ssh://' in self.url_rw:
50+
return '{}/{}.git'.format(self.url_rw, repo)
51+
else:
52+
return '{}:{}.git'.format(self.url_rw, repo)
53+
else:
54+
raise ArgumentError("Cannot tell how to handle this url: `{}/{}`!".format(namespace, repo))
4955

5056
def delete(self, repo, user=None):
5157
raise NotImplementedError("GitBucket doesn't suport this action now.")

0 commit comments

Comments
 (0)