Skip to content

Commit c526a5c

Browse files
committed
Fixed guessing of reposlug based on current repository
1 parent 4ca2051 commit c526a5c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

git_repo/repo.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,20 @@ def init(self): # pragma: no cover
154154
def _guess_repo_slug(self, repository, service):
155155
config = repository.config_reader()
156156
target = service.name
157-
for section_name in config.sections():
158-
if 'remote' in section_name:
159-
section = dict(config.items(section_name))
160-
if target in section['url']:
161-
if section['url'].startswith('https'):
162-
*_, user, name = section['url'].rstrip('.git').split('/')
163-
self.set_repo_slug('/'.join([user, name]))
164-
break
165-
elif section['url'].startswith('git@'):
166-
_, repo_slug = section['url'].rstrip('.git').split(':')
167-
self.set_repo_slug(repo_slug)
168-
break
157+
for remote in repository.remotes:
158+
for url in remote.urls:
159+
if url.startswith('https'):
160+
if '.git' in url:
161+
url = url[:-4]
162+
*_, user, name = url.split('/')
163+
self.set_repo_slug('/'.join([user, name]))
164+
break
165+
elif url.startswith('git@'):
166+
if '.git' in url:
167+
url = url[:-4]
168+
_, repo_slug = url.split(':')
169+
self.set_repo_slug(repo_slug)
170+
break
169171

170172
def get_service(self, lookup_repository=True):
171173
if not lookup_repository:
@@ -181,7 +183,7 @@ def get_service(self, lookup_repository=True):
181183
except InvalidGitRepositoryError:
182184
raise FileNotFoundError('Cannot find path to the repository.')
183185
service = RepositoryService.get_service(repository, self.target)
184-
if not self.repo_slug:
186+
if not self.repo_name:
185187
self._guess_repo_slug(repository, service)
186188
return service
187189

0 commit comments

Comments
 (0)