From a02c31789ebf582709bec11b9d88f7f06c9d8510 Mon Sep 17 00:00:00 2001 From: Yevgen Lasman Date: Tue, 19 Jan 2021 18:43:20 +0200 Subject: [PATCH] Bitbucket: Check project existence --- atlassian/bitbucket/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/atlassian/bitbucket/__init__.py b/atlassian/bitbucket/__init__.py index 91ff87b2f..ca2db46ab 100644 --- a/atlassian/bitbucket/__init__.py +++ b/atlassian/bitbucket/__init__.py @@ -2,6 +2,7 @@ import logging from deprecated import deprecated +from requests import HTTPError from .base import BitbucketBase from atlassian.bitbucket.cloud import Cloud @@ -296,6 +297,21 @@ def project(self, key): url = self._url_project(key) return self.get(url) or {} + def project_exists(self, project_key): + """ + Check if project with the provided project key exists and available. + :param project_key: Key of the project where to check for repository. + :return: False is requested repository doesn't exist in the project or not accessible to the requestor + """ + exists = False + try: + self.project(project_key) + exists = True + except HTTPError as e: + if e.response.status_code in (401, 404): + pass + return exists + def update_project(self, key, **params): """ Update project