Skip to content

Commit 4fb081b

Browse files
Adding Typehints for jira.py (#1418)
* adding type hints * avoiding errors about override signature * adding various types packages to requirements-dev.txt * adding type hints * using alias for json response type * allowing test action to be run manually to help troubleshoot failures * cannot utilize the workflow_dispatch on branches until it's been merged into main/master. * black formatting is different in 3.7 * urllib3 is imported directly, thus should be in the reqs * cannot use new style annotations with older versions of python * future annotations aren't available in 3.6 * looks like bandit is not able to be installed in python3.6 * ignoring the list return vs the typical dictionary * avoiding black formatter inconsistencies between 23.3 and 24.x * minor cleanup after rebase * enforcing flake8 TC006 rule * fixing black formatting * mypy fixes * adding types-jmespath to requirements-dev.txt * adding types-oauthlib to reqs dev * mypy fixes - incompatible return types * rebased from master and updated missing annotations for arguments * adjust for mypy --------- Co-authored-by: Gonchik Tsymzhitov <[email protected]>
1 parent 2cc0d77 commit 4fb081b

File tree

11 files changed

+1210
-707
lines changed

11 files changed

+1210
-707
lines changed

atlassian/bitbucket/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# coding=utf-8
22
import logging
33
from enum import Enum
4+
from typing import Optional
45

56
from deprecated import deprecated
67
from requests import HTTPError
78

8-
from .base import BitbucketBase
99
from atlassian.bitbucket.cloud import Cloud
1010

11+
from .base import BitbucketBase
12+
1113
log = logging.getLogger(__name__)
1214

1315

@@ -1891,7 +1893,7 @@ def get_pull_requests_participants(
18911893

18921894
def assign_pull_request_participant_role(
18931895
self, project_key: str, repository_slug: str, pull_request_id: int, role: str, user: str
1894-
) -> dict:
1896+
) -> Optional[dict]:
18951897
"""
18961898
Assign a role to a user for a pull request
18971899
:param project_key: The project key
@@ -2117,7 +2119,9 @@ def add_pull_request_blocker_comment(
21172119
data = {"text": text, "severity": severity}
21182120
return self.post(url, data=data)
21192121

2120-
def search_pull_request_blocker_comment(self, project_key: str, repository_slug: str, pull_request_id: int) -> dict:
2122+
def search_pull_request_blocker_comment(
2123+
self, project_key: str, repository_slug: str, pull_request_id: int
2124+
) -> Optional[dict]:
21212125
"""
21222126
Get all comments that block the merge of a pull request
21232127
:param project_key: The project key

atlassian/bitbucket/cloud/repositories/repositoryVariables.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# coding=utf-8
2-
32
from ..base import BitbucketCloudBase
43

54

65
class RepositoryVariables(BitbucketCloudBase):
76
def __init__(self, url, *args, **kwargs):
87
super(RepositoryVariables, self).__init__(url, *args, **kwargs)
98

10-
def __get_object(self, data):
9+
def __get_object(self, data) -> "RepositoryVariable":
1110
return RepositoryVariable(
1211
self.url_joiner(self.url, data["uuid"]),
1312
data,
@@ -61,7 +60,7 @@ def each(self, q=None, sort=None):
6160

6261
return
6362

64-
def get(self, uuid):
63+
def get(self, uuid: str): # type: ignore[override]
6564
"""
6665
Returns the pipeline with the uuid in this repository.
6766

atlassian/confluence.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import os
66
import re
77
import time
8+
from typing import cast
89

10+
import requests
911
from bs4 import BeautifulSoup
1012
from deprecated import deprecated
11-
import requests
1213
from requests import HTTPError
1314

1415
from atlassian import utils
16+
1517
from .errors import (
1618
ApiConflictError,
1719
ApiError,
@@ -1644,7 +1646,7 @@ def set_page_label(self, page_id, label):
16441646

16451647
return response
16461648

1647-
def remove_page_label(self, page_id, label):
1649+
def remove_page_label(self, page_id: str, label: str):
16481650
"""
16491651
Delete Confluence page label
16501652
:param page_id: content_id format
@@ -2740,13 +2742,13 @@ def get_space_export(self, space_key: str, export_type: str) -> str:
27402742
:return: The URL to download the exported file.
27412743
"""
27422744

2743-
def get_atl_request(url: str):
2745+
def get_atl_request(link: str):
27442746
# Nested function used to get atl_token used for XSRF protection.
27452747
# This is only applicable to html/csv/xml space exports
27462748
try:
2747-
response = self.get(url, advanced_mode=True)
2749+
response = self.get(link, advanced_mode=True)
27482750
parsed_html = BeautifulSoup(response.text, "html.parser")
2749-
atl_token = parsed_html.find("input", {"name": "atl_token"}).get("value")
2751+
atl_token = parsed_html.find("input", {"name": "atl_token"}).get("value") # type: ignore[union-attr]
27502752
return atl_token
27512753
except Exception as e:
27522754
raise ApiError("Problems with getting the atl_token for get_space_export method :", reason=e)
@@ -2798,17 +2800,17 @@ def get_atl_request(url: str):
27982800
parsed_html = BeautifulSoup(response.text, "html.parser")
27992801
# Getting the poll URL to get the export progress status
28002802
try:
2801-
poll_url = parsed_html.find("meta", {"name": "ajs-pollURI"}).get("content")
2803+
poll_url = cast("str", parsed_html.find("meta", {"name": "ajs-pollURI"}).get("content")) # type: ignore[union-attr]
28022804
except Exception as e:
28032805
raise ApiError("Problems with getting the poll_url for get_space_export method :", reason=e)
28042806
running_task = True
28052807
while running_task:
28062808
try:
2807-
progress_response = self.get(poll_url)
2808-
log.info("Space" + space_key + " export status: " + progress_response["message"])
2809-
if progress_response["complete"]:
2810-
parsed_html = BeautifulSoup(progress_response["message"], "html.parser")
2811-
download_url = parsed_html.find("a", {"class": "space-export-download-path"}).get("href")
2809+
progress_response = self.get(poll_url) or {}
2810+
log.info(f"Space {space_key} export status: {progress_response.get('message', 'None')}")
2811+
if progress_response is not {} and progress_response.get("complete"):
2812+
parsed_html = BeautifulSoup(progress_response.get("message"), "html.parser")
2813+
download_url = cast("str", parsed_html.find("a", {"class": "space-export-download-path"}).get("href")) # type: ignore
28122814
if self.url in download_url:
28132815
return download_url
28142816
else:

0 commit comments

Comments
 (0)