@@ -69,15 +69,32 @@ class RepositoryService:
69
69
@staticmethod
70
70
def get_config_path ():
71
71
home_dir = os .environ ['HOME' ]
72
- home_conf = os .path .join (home_dir , '.gitconfig' )
73
- xdg_conf = os .path .join (home_dir , '.git' , 'config' )
74
- if not os .path .exists (xdg_conf ):
75
- if os .path .exists (home_conf ):
76
- return home_conf
77
- return xdg_conf
72
+ try :
73
+ from xdg .BaseDirectory import xdg_config_home
74
+ except ImportError :
75
+ xdg_config_home = os .path .join (home_dir , ".config" )
76
+ for config in [
77
+ os .path .join (home_dir , '.gitconfig' ),
78
+ os .path .join (xdg_config_home , 'git' ),
79
+ ]:
80
+ if os .path .exists (config ):
81
+ return config
82
+ raise ResourceNotFoundError ('User\' s Git configuration file not found!' )
78
83
79
84
@staticmethod
80
- def guess_repo_slug (repository , service , resolve_targets = None ):
85
+ def convert_url_into_slug (url ):
86
+ if url .endswith ('.git' ):
87
+ url = url [:- 4 ]
88
+ # strip http://, https:// and ssh://
89
+ if '://' in url :
90
+ * _ , user , name = url .split ('/' )
91
+ return '/' .join ([user , name ])
92
+ # scp-style URL
93
+ elif '@' in url and ':' in url :
94
+ return url .split (':' )[- 1 ]
95
+
96
+ @classmethod
97
+ def guess_repo_slug (cls , repository , service , resolve_targets = None ):
81
98
if resolve_targets :
82
99
targets = [target .format (service = service .name ) for target in resolve_targets ]
83
100
else :
0 commit comments