5
5
6
6
from ..service import register_target
7
7
from .github import GithubService
8
+ from ...exceptions import ArgumentError
8
9
9
10
import github3
10
11
@@ -15,15 +16,11 @@ class GitbucketService(GithubService):
15
16
def __init__ (self , * args , ** kwarg ):
16
17
super (GitbucketService , self ).__init__ (* args , ** kwarg )
17
18
18
- def connect (self ):
19
- self .gh = github3 .GitHubEnterprise (self .build_url (self ))
20
- super (GitbucketService , self ).connect ()
21
-
22
19
@classmethod
23
20
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> ' )
27
24
## this code maybe works when GitBucket supports add access token API.
28
25
#print("build_url: ", cls.build_url(cls))
29
26
#import platform
@@ -42,10 +39,19 @@ def get_auth_token(cls, login, password, prompt=None):
42
39
# raise err
43
40
44
41
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 ))
49
55
50
56
def delete (self , repo , user = None ):
51
57
raise NotImplementedError ("GitBucket doesn't suport this action now." )
0 commit comments