Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions atlassian/bamboo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ def _get_generator(
response.raise_for_status()
response = response.json()
except HTTPError as e:
logging.error(f"Broken response: {e}")
yield e
return
log.error(f"Broken response: {e}")
raise
try:
results = response[elements_key]
size = 0
Expand All @@ -62,8 +61,8 @@ def _get_generator(
size += 1
yield r
except TypeError:
logging.error(f"Broken response: {response}")
yield response
log.error(f"Broken response: {response}")
raise

def base_list_call(
self,
Expand Down Expand Up @@ -759,9 +758,9 @@ def delete_build_result(self, build_key):
:param build_key: Take full build key, example: PROJECT-PLAN-8
"""
custom_resource = "/build/admin/deletePlanResults.action"
build_key = build_key.split("-")
plan_key = f"{build_key[0]}-{build_key[1]}"
build_number = build_key[2]
build_key_parts = build_key.split("-")
plan_key = "-".join(build_key_parts[:-1])
build_number = build_key_parts[-1]
params = {"buildKey": plan_key, "buildNumber": build_number}
return self.post(custom_resource, params=params, headers=self.form_token_headers)

Expand Down Expand Up @@ -906,7 +905,6 @@ def delete_label(self, project_key, plan_key, build_number, label):
resource = f"result/{project_key}-{plan_key}-{build_number}/label/{label}"
return self.delete(self.resource_url(resource))

@property
def get_projects(self, start=0, limit=25):
"""Method used to list all projects defined in Bamboo.
Projects without any plan are not listed.
Expand Down Expand Up @@ -2430,15 +2428,16 @@ def upload_plugin(self, plugin_path):
:param plugin_path:
:return:
"""
files = {"plugin": open(plugin_path, "rb")}
upm_token = self.request(
method="GET",
path="rest/plugins/1.0/",
headers=self.no_check_headers,
trailing=True,
).headers["upm-token"]
url = f"rest/plugins/1.0/?token={upm_token}"
return self.post(url, files=files, headers=self.no_check_headers)
with open(plugin_path, "rb") as plugin_file:
files = {"plugin": plugin_file}
return self.post(url, files=files, headers=self.no_check_headers)

def disable_plugin(self, plugin_key):
"""
Expand Down
23 changes: 8 additions & 15 deletions atlassian/bitbucket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,10 @@ def project_exists(self, project_key):
self.project(project_key)
exists = True
except HTTPError as e:
if e.response.status_code in (401, 404):
if e.response.status_code == 404:
pass
else:
raise
return exists

def update_project(self, key, **params):
Expand Down Expand Up @@ -1021,9 +1023,10 @@ def repo_exists(self, project_key, repository_slug):
self.get_repo(project_key, repository_slug)
exists = True
except HTTPError as e:
if e.response.status_code in (401, 404):
if e.response.status_code == 404:
pass
return exists
else:
raise

def update_repo(self, project_key, repository_slug, **params):
"""
Expand Down Expand Up @@ -3213,12 +3216,7 @@ def get_repo_project_conditions(self, project_key, repo_key):
:return:
"""
response = self.get_repo_conditions(project_key, repo_key)
count = 0
for condition in response:
if condition["scope"]["type"] == "REPOSITORY":
del response[count]
count += 1
return response
return [condition for condition in response if condition["scope"]["type"] == "PROJECT"]

def get_repo_repo_conditions(self, project_key, repo_key):
"""
Expand All @@ -3232,12 +3230,7 @@ def get_repo_repo_conditions(self, project_key, repo_key):
:return:
"""
response = self.get_repo_conditions(project_key, repo_key)
count = 0
for condition in response:
if condition["scope"]["type"] == "PROJECT":
del response[count]
count += 1
return response
return [condition for condition in response if condition["scope"]["type"] == "REPOSITORY"]

def _url_repo_condition(self, project_key, repo_key, id_condition=None):
return "{}/condition/{}".format(
Expand Down
4 changes: 3 additions & 1 deletion atlassian/bitbucket/cloud/repositories/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ def exists(self, repository, by="slug"):
self.get(repository, by)
exists = True
except HTTPError as e:
if e.response.status_code in (401, 404):
if e.response.status_code == 404:
pass
else:
raise
except Exception as e:
if not str(e) == f"Unknown repository {by} '{repository}'":
raise e
Expand Down
4 changes: 3 additions & 1 deletion atlassian/bitbucket/cloud/workspaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def exists(self, workspace):
self.get(workspace)
exists = True
except HTTPError as e:
if e.response.status_code in (401, 404):
if e.response.status_code == 404:
pass
else:
raise
return exists


Expand Down
4 changes: 3 additions & 1 deletion atlassian/bitbucket/cloud/workspaces/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ def exists(self, project, by="key"):
self.get(project, by)
exists = True
except HTTPError as e:
if e.response.status_code in (401, 404):
if e.response.status_code == 404:
pass
else:
raise
except Exception as e:
if not str(e) == f"Unknown project {by} '{project}'":
raise e
Expand Down
4 changes: 3 additions & 1 deletion atlassian/bitbucket/server/projects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ def exists(self, project, by="key"):
self.get(project, by)
exists = True
except HTTPError as e:
if e.response.status_code in (401, 404):
if e.response.status_code == 404:
pass
else:
raise
except Exception as e:
if not str(e) == f"Unknown project {by} '{project}'":
raise e
Expand Down
4 changes: 3 additions & 1 deletion atlassian/bitbucket/server/projects/repos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ def exists(self, repository, by="slug"):
self.get(repository, by)
exists = True
except HTTPError as e:
if e.response.status_code in (401, 404):
if e.response.status_code == 404:
pass
else:
raise
except Exception as e:
if not str(e) == f"Unknown repository {by} '{repository}'":
raise e
Expand Down
2 changes: 1 addition & 1 deletion atlassian/cloud_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def search_users_in_organization(
params["emailUsernames"] = email_usernames
if email_domains:
params["emailDomains"] = email_domains
if is_suspended:
if is_suspended is not None:
params["isSuspended"] = is_suspended
if expand:
params["expand"] = expand
Expand Down
9 changes: 8 additions & 1 deletion atlassian/confluence/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,14 @@ def _get_paged(
# query. Reusing the already-resolved endpoint preserves both
# ``/wiki`` and API-gateway tenant prefixes.
parsed_next = urlparse(url)
if getattr(self, "api_version", None) == 2 and parsed_next.query and not parsed_next.scheme:
next_path = parsed_next.path.strip("/")
current_path = urlparse(current_url).path.strip("/")
if (
str(getattr(self, "api_version", "")) == "2"
and parsed_next.query
and not parsed_next.scheme
and (not next_path or next_path == current_path)
):
url = current_url
params = dict(parse_qsl(parsed_next.query, keep_blank_values=True))
trailing = False
Expand Down
Loading
Loading