Skip to content

Commit 5b27a0f

Browse files
Bitbucket: Check for a repository existence (#709)
Co-authored-by: Yevgen Lasman <[email protected]>
1 parent 6cdf672 commit 5b27a0f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

atlassian/bitbucket/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
from deprecated import deprecated
5+
from requests import HTTPError
56

67
from .base import BitbucketBase
78
from atlassian.bitbucket.cloud import Cloud
@@ -680,6 +681,22 @@ def get_repo(self, project_key, repository_slug):
680681
url = self._url_repo(project_key, repository_slug)
681682
return self.get(url)
682683

684+
def repo_exists(self, project_key, repository_slug):
685+
"""
686+
Check if given combination of project and repository exists and available.
687+
:param project_key: Key of the project where to check for repository.
688+
:param repository_slug: url-compatible repository identifier to look for.
689+
:return: False is requested repository doesn't exist in the project or not accessible to the requestor
690+
"""
691+
exists = False
692+
try:
693+
self.get_repo(project_key, repository_slug)
694+
exists = True
695+
except HTTPError as e:
696+
if e.response.status_code in (401, 404):
697+
pass
698+
return exists
699+
683700
def update_repo(self, project_key, repository_slug, **params):
684701
"""
685702
Update a repository in a project. This operates based on slug not name which may

0 commit comments

Comments
 (0)