Update dev dependencies (includes breaking changes)

This commit is contained in:
Dale Myers 2021-11-23 11:57:38 +00:00
Родитель a5962fd649
Коммит dfd60731d7
14 изменённых файлов: 637 добавлений и 413 удалений

791
poetry.lock сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -31,19 +31,20 @@ classifiers = [
]
[tool.poetry.dependencies]
python = "^3.6"
python = "^3.6.2"
deserialize = "^1.5.1"
requests = "^2.21"
tenacity = "^6.2.0"
[tool.poetry.dev-dependencies]
attrs = "=19.1.0" # This is required until this issue is fixed: https://stackoverflow.com/questions/58189683/typeerror-attrib-got-an-unexpected-keyword-argument-convert
black = "=19.10b0"
mypy = "=0.770"
pylint = "=2.4.4"
pytest = "=5.4.1"
pytest-cov = "=2.8.1"
black = "=21.11b1"
mypy = "=0.910"
pylint = "=2.11.1"
pytest = "=6.2.5"
pytest-cov = "=3.0.0"
toml = "^0.10.0"
types-requests = "^2.21"
types-toml = "^0.10.0"
[build-system]

Просмотреть файл

@ -173,7 +173,11 @@ class ADOClient:
)
def list_all_pull_requests(
self, *, branch_name: Optional[str] = None, project_id: str, repository_id: str,
self,
*,
branch_name: Optional[str] = None,
project_id: str,
repository_id: str,
) -> ADOResponse:
"""Get the pull requests for a branch from ADO.

Просмотреть файл

@ -13,7 +13,7 @@ import urllib.parse
import deserialize
from simple_ado.base_client import ADOBaseClient
from simple_ado.http_client import ADOHTTPClient, ADOResponse
from simple_ado.http_client import ADOHTTPClient
from simple_ado.models import AuditActionInfo
@ -35,7 +35,7 @@ class ADOAuditClient(ADOBaseClient):
:returns: The ADO response with the data in it
"""
self.log.debug(f"Getting audit actions")
self.log.debug("Getting audit actions")
parameters = {"api-version": "6.0-preview.1"}

Просмотреть файл

@ -172,7 +172,12 @@ class ADOGitClient(ADOBaseClient):
return self.http_client.decode_response(response)
def diff_between_commits(
self, *, base_commit: str, target_commit: str, project_id: str, repository_id: str,
self,
*,
base_commit: str,
target_commit: str,
project_id: str,
repository_id: str,
) -> ADOResponse:
"""Get the diff between two commits.
@ -220,7 +225,12 @@ class ADOGitClient(ADOBaseClient):
skip += 100
def download_zip(
self, *, branch: str, output_path: str, project_id: str, repository_id: str,
self,
*,
branch: str,
output_path: str,
project_id: str,
repository_id: str,
) -> None:
"""Download the zip of the branch specified.
@ -309,7 +319,7 @@ class ADOGitClient(ADOBaseClient):
# pylint: disable=too-complex
self.log.debug(f"Getting refs")
self.log.debug("Getting refs")
request_url = f"{self.http_client.api_endpoint(project_id=project_id)}/git/repositories/{repository_id}/refs?"
@ -390,7 +400,11 @@ class ADOGitClient(ADOBaseClient):
return self.http_client.decode_response(response)
def update_refs(
self, *, updates: List[ADOReferenceUpdate], project_id: str, repository_id: str,
self,
*,
updates: List[ADOReferenceUpdate],
project_id: str,
repository_id: str,
) -> ADOResponse:
"""Update a list of references.
@ -433,24 +447,24 @@ class ADOGitClient(ADOBaseClient):
class VersionControlRecursionType(enum.Enum):
"""Specifies the level of recursion to use when getting an item."""
full = "full"
none = "none"
one_level = "oneLevel"
one_level_plus_nested_empty_folders = "oneLevelPlusNestedEmptyFolders"
FULL = "full"
NONE = "none"
ONE_LEVEL = "oneLevel"
ONE_LEVEL_PLUS_NESTED_EMPTY_FOLDERS = "oneLevelPlusNestedEmptyFolders"
class GitVersionOptions(enum.Enum):
"""Version options."""
first_parent = "firstParent"
none = "none"
previous_change = "previousChange"
FIRST_PARENT = "firstParent"
NONE = "none"
PREVIOUS_CHANGE = "previousChange"
class GitVersionType(enum.Enum):
"""Version type. Determines how the ID of an item is interpreted."""
branch = "branch"
commit = "commit"
tag = "tag"
BRANCH = "branch"
COMMIT = "commit"
TAG = "tag"
# pylint: disable=too-many-locals
def get_item(
@ -489,7 +503,7 @@ class ADOGitClient(ADOBaseClient):
:returns: The ADO response with the data in it
"""
self.log.debug(f"Getting item")
self.log.debug("Getting item")
request_url = f"{self.http_client.api_endpoint(project_id=project_id)}/git/repositories/{repository_id}/items?"
@ -532,10 +546,10 @@ class ADOGitClient(ADOBaseClient):
class BlobFormat(enum.Enum):
"""The type of format to get a blob in."""
json = "json"
zip = "zip"
text = "text"
octetstream = "octetstream"
JSON = "json"
ZIP = "zip"
TEXT = "text"
OCTETSTREAM = "octetstream"
def get_blob(
self,
@ -563,7 +577,7 @@ class ADOGitClient(ADOBaseClient):
:returns: The ADO response with the data in it
"""
self.log.debug(f"Getting blob")
self.log.debug("Getting blob")
request_url = self.http_client.api_endpoint(
is_default_collection=False, project_id=project_id
@ -590,14 +604,19 @@ class ADOGitClient(ADOBaseClient):
response = self.http_client.get(request_url)
if blob_format == ADOGitClient.BlobFormat.text:
if blob_format == ADOGitClient.BlobFormat.TEXT:
self.http_client.validate_response(response)
return response.text
return self.http_client.decode_response(response)
def get_blobs(
self, *, blob_ids: List[str], output_path: str, project_id: str, repository_id: str,
self,
*,
blob_ids: List[str],
output_path: str,
project_id: str,
repository_id: str,
) -> ADOResponse:
"""Get a git item.
@ -611,7 +630,7 @@ class ADOGitClient(ADOBaseClient):
:raises FileExistsError: If the output path already exists
"""
self.log.debug(f"Getting blobs")
self.log.debug("Getting blobs")
request_url = self.http_client.api_endpoint(
is_default_collection=False, project_id=project_id

Просмотреть файл

@ -383,7 +383,8 @@ class ADOHTTPClient:
if response.status_code < 200 or response.status_code >= 300:
raise ADOHTTPException(
f"ADO returned a non-200 status code, configuration={self}", response,
f"ADO returned a non-200 status code, configuration={self}",
response,
)
def decode_response(self, response: requests.models.Response) -> ADOResponse:
@ -403,8 +404,8 @@ class ADOHTTPClient:
try:
content: ADOResponse = response.json()
except:
raise ADOException("The response did not contain JSON")
except Exception as ex:
raise ADOException("The response did not contain JSON") from ex
return content
@ -423,8 +424,8 @@ class ADOHTTPClient:
try:
value: ADOResponse = response_data["value"]
return value
except:
raise ADOException("The response was invalid (did not contain a value).")
except Exception as ex:
raise ADOException("The response was invalid (did not contain a value).") from ex
def construct_headers(
self, *, additional_headers: Optional[Dict[str, str]] = None
@ -438,7 +439,7 @@ class ADOHTTPClient:
headers = {"Accept": "application/json"}
for header_name, header_value in self.extra_headers:
for header_name, header_value in self.extra_headers.items():
headers[header_name] = header_value
if additional_headers is None:

Просмотреть файл

@ -7,17 +7,22 @@ from typing import Any, Dict, Optional
class OperationType(enum.Enum):
"""An ADO operation."""
add = "add"
copy = "copy"
move = "move"
remove = "remove"
replace = "replace"
test = "test"
ADD = "add"
COPY = "copy"
MOVE = "move"
REMOVE = "remove"
REPLACE = "replace"
TEST = "test"
class PatchOperation:
"""Represents a PATCH operation."""
operation: OperationType
path: str
value: Optional[Any]
from_path: Optional[str]
def __init__(
self,
operation: OperationType,
@ -37,7 +42,7 @@ class PatchOperation:
self.value = value
self.from_path = from_path
def serialize(self) -> Dict[str, str]:
def serialize(self) -> Dict[str, Any]:
"""Serialize for sending to ADO.
:returns: A dictionary.
@ -60,11 +65,11 @@ class AddOperation(PatchOperation):
"""Represents an add PATCH operation."""
def __init__(self, field: str, value: Any):
super().__init__(OperationType.add, field, value)
super().__init__(OperationType.ADD, field, value)
class DeleteOperation(PatchOperation):
"""Represents a delete PATCH operation."""
def __init__(self, field: str):
super().__init__(OperationType.remove, field, None)
super().__init__(OperationType.REMOVE, field, None)

Просмотреть файл

@ -18,9 +18,9 @@ from simple_ado.http_client import ADOHTTPClient, ADOResponse
class TaskAgentPoolActionFilter(enum.Enum):
"""Represents an agent pool action filter."""
manage = "manage"
none = "none"
use = "use"
MANAGE = "manage"
NONE = "none"
USE = "use"
class ADOPoolsClient(ADOBaseClient):
@ -48,7 +48,7 @@ class ADOPoolsClient(ADOBaseClient):
"""
request_url = self.http_client.api_endpoint(is_default_collection=False)
request_url += f"/distributedtask/pools?"
request_url += "/distributedtask/pools?"
parameters = {"api-version": "5.1"}

Просмотреть файл

@ -126,7 +126,11 @@ class ADOPullRequestClient(ADOBaseClient):
self.log.debug(f"Creating comment: ({self.pull_request_id}) {comment_text}")
comment = ADOComment(comment_text, comment_location)
return self.create_comment(comment, status=status, comment_identifier=comment_identifier,)
return self.create_comment(
comment,
status=status,
comment_identifier=comment_identifier,
)
def create_comment(
self,
@ -225,7 +229,10 @@ class ADOPullRequestClient(ADOBaseClient):
)
def create_thread_list(
self, *, threads: List[ADOComment], comment_identifier: Optional[str] = None,
self,
*,
threads: List[ADOComment],
comment_identifier: Optional[str] = None,
) -> None:
"""Create a list of threads
@ -296,7 +303,7 @@ class ADOPullRequestClient(ADOBaseClient):
+ f"/pullRequests/{self.pull_request_id}/statuses?api-version=4.0-preview"
)
body = {
body: Dict[str, Any] = {
"state": state.value,
"description": description,
"context": {"name": context, "genre": identifier},
@ -335,8 +342,8 @@ class ADOPullRequestClient(ADOBaseClient):
try:
properties = thread["properties"]
except:
raise ADOException("Could not find properties in thread: " + str(thread))
except Exception as ex:
raise ADOException("Could not find properties in thread: " + str(thread)) from ex
if properties is None:
return False

Просмотреть файл

@ -121,9 +121,9 @@ class ADOSecurityClient(ADOBaseClient):
"settings": {
"buildDefinitionId": build_definition_id,
"displayName": None,
"queueOnSourceUpdateOnly": False,
"queueOnSourceUpdateOnly": build_expiration is not None,
"manualQueueOnly": False,
"validDuration": 0,
"validDuration": build_expiration if build_expiration is not None else 0,
"scope": [
{
"refName": f"refs/heads/{branch}",
@ -134,15 +134,16 @@ class ADOSecurityClient(ADOBaseClient):
},
}
if build_expiration:
body["settings"]["queueOnSourceUpdateOnly"] = True
body["settings"]["validDuration"] = build_expiration
response = self.http_client.post(request_url, json_data=body)
return self.http_client.decode_response(response)
def add_branch_required_reviewers_policy(
self, *, branch: str, identities: List[str], project_id: str, repository_id: str,
self,
*,
branch: str,
identities: List[str],
project_id: str,
repository_id: str,
) -> ADOResponse:
"""Adds required reviewers when opening PRs against a given branch.
@ -236,7 +237,12 @@ class ADOSecurityClient(ADOBaseClient):
return self.http_client.decode_response(response)
def set_branch_work_item_policy(
self, *, branch: str, required: bool = True, project_id: str, repository_id: str,
self,
*,
branch: str,
required: bool = True,
project_id: str,
repository_id: str,
) -> ADOResponse:
"""Set the work item policy for a branch.
@ -377,16 +383,19 @@ class ADOSecurityClient(ADOBaseClient):
"type": response_data["descriptorIdentityType"],
"id": response_data["descriptorIdentifier"],
}
except:
except Exception as ex:
raise ADOException(
"Could not determine descriptor info for team_foundation_id: "
+ str(team_foundation_id)
)
) from ex
return descriptor_info
def _generate_permission_set_token(
self, branch: str, project_id: str, repository_id: str,
self,
branch: str,
project_id: str,
repository_id: str,
) -> str:
"""Generate the token required for reading identity details and writing permissions.
@ -400,7 +409,12 @@ class ADOSecurityClient(ADOBaseClient):
encoded_branch = branch.replace("/", "^")
return f"repoV2/{project_id}/{repository_id}/refs^heads^{encoded_branch}/"
def _generate_updates_token(self, branch: str, project_id: str, repository_id: str,) -> str:
def _generate_updates_token(
self,
branch: str,
project_id: str,
repository_id: str,
) -> str:
"""Generate the token required for updating permissions.
:param str branch: The git branch of interest

Просмотреть файл

@ -8,9 +8,7 @@
import logging
from simple_ado.base_client import ADOBaseClient
from simple_ado.exceptions import ADOException
from simple_ado.http_client import ADOHTTPClient
from simple_ado.types import TeamFoundationId
class ADOUserClient(ADOBaseClient):

Просмотреть файл

@ -69,7 +69,9 @@ class ADOWikiClient(ADOBaseClient):
)
response = self.http_client.patch(
request_url,
json_data={"content": content,},
json_data={
"content": content,
},
additional_headers={
"Content-Type": "application/json",
"If-Match": current_version_etag,

Просмотреть файл

@ -63,38 +63,38 @@ class DeleteBatchRequest(BatchRequest):
class WorkItemRelationType(enum.Enum):
"""Defines the various relationship types between work items."""
produces_for = "System.LinkTypes.Remote.Dependency-Forward"
consumes_from = "System.LinkTypes.Remote.Dependency-Reverse"
PRODUCES_FOR = "System.LinkTypes.Remote.Dependency-Forward"
CONSUMES_FROM = "System.LinkTypes.Remote.Dependency-Reverse"
duplicate = "System.LinkTypes.Duplicate-Forward"
duplicate_of = "System.LinkTypes.Duplicate-Reverse"
DUPLICATE = "System.LinkTypes.Duplicate-Forward"
DUPLICATE_OF = "System.LinkTypes.Duplicate-Reverse"
blocked_by = "Microsoft.VSTS.BlockingLink-Forward"
blocking = "Microsoft.VSTS.BlockingLink-Reverse"
BLOCKED_BY = "Microsoft.VSTS.BlockingLink-Forward"
BLOCKING = "Microsoft.VSTS.BlockingLink-Reverse"
referenced_by = "Microsoft.VSTS.TestCase.SharedParameterReferencedBy-Forward"
references = "Microsoft.VSTS.TestCase.SharedParameterReferencedBy-Reverse"
REFERENCED_BY = "Microsoft.VSTS.TestCase.SharedParameterReferencedBy-Forward"
REFERENCES = "Microsoft.VSTS.TestCase.SharedParameterReferencedBy-Reverse"
tested_by = "Microsoft.VSTS.Common.TestedBy-Forward"
tests = "Microsoft.VSTS.Common.TestedBy-Reverse"
TESTED_BY = "Microsoft.VSTS.Common.TestedBy-Forward"
TESTS = "Microsoft.VSTS.Common.TestedBy-Reverse"
test_case = "Microsoft.VSTS.TestCase.SharedStepReferencedBy-Forward"
shared_steps = "Microsoft.VSTS.TestCase.SharedStepReferencedBy-Reverse"
TEST_CASE = "Microsoft.VSTS.TestCase.SharedStepReferencedBy-Forward"
SHARED_STEPS = "Microsoft.VSTS.TestCase.SharedStepReferencedBy-Reverse"
successor = "System.LinkTypes.Dependency-Forward"
predecessor = "System.LinkTypes.Dependency-Reverse"
SUCCESSOR = "System.LinkTypes.Dependency-Forward"
PREDECESSOR = "System.LinkTypes.Dependency-Reverse"
child = "System.LinkTypes.Hierarchy-Forward"
parent = "System.LinkTypes.Hierarchy-Reverse"
CHILD = "System.LinkTypes.Hierarchy-Forward"
PARENT = "System.LinkTypes.Hierarchy-Reverse"
remote_related = "System.LinkTypes.Remote.Related"
related = "System.LinkTypes.Related"
REMOTE_RELATED = "System.LinkTypes.Remote.Related"
RELATED = "System.LinkTypes.Related"
attached_file = "AttachedFile"
ATTACHED_FILE = "AttachedFile"
hyperlink = "Hyperlink"
HYPERLINK = "Hyperlink"
artifact_link = "ArtifactLink"
ARTIFACT_LINK = "ArtifactLink"
class ADOWorkItemsClient(ADOBaseClient):
@ -168,7 +168,7 @@ class ADOWorkItemsClient(ADOBaseClient):
)
request_url += f"?bypassRules={boolstr(bypass_rules)}"
request_url += f"&suppressNotifications={boolstr(supress_notifications)}"
request_url += f"&api-version=4.1"
request_url += "&api-version=4.1"
response = self.http_client.patch(
request_url,
@ -229,7 +229,8 @@ class ADOWorkItemsClient(ADOBaseClient):
# Attach it to the ticket
operation = AddOperation(
"/relations/-", {"rel": "AttachedFile", "url": url, "attributes": {"comment": ""}},
"/relations/-",
{"rel": "AttachedFile", "url": url, "attributes": {"comment": ""}},
)
request_url = (
@ -237,7 +238,7 @@ class ADOWorkItemsClient(ADOBaseClient):
)
request_url += f"?bypassRules={boolstr(bypass_rules)}"
request_url += f"&suppressNotifications={boolstr(supress_notifications)}"
request_url += f"&api-version=4.1"
request_url += "&api-version=4.1"
response = self.http_client.patch(
request_url,
@ -283,7 +284,7 @@ class ADOWorkItemsClient(ADOBaseClient):
request_url = f"{self.http_client.api_endpoint(project_id=project_id)}/wit/workitems/{parent_identifier}"
request_url += f"?bypassRules={boolstr(bypass_rules)}"
request_url += f"&suppressNotifications={boolstr(supress_notifications)}"
request_url += f"&api-version=4.1"
request_url += "&api-version=4.1"
response = self.http_client.patch(
request_url,
@ -353,7 +354,7 @@ class ADOWorkItemsClient(ADOBaseClient):
return self._add_link(
parent_identifier=identifier,
child_url=hyperlink,
relation_type=WorkItemRelationType.hyperlink,
relation_type=WorkItemRelationType.HYPERLINK,
project_id=project_id,
bypass_rules=bypass_rules,
supress_notifications=supress_notifications,
@ -390,7 +391,7 @@ class ADOWorkItemsClient(ADOBaseClient):
)
request_url += f"?bypassRules={boolstr(bypass_rules)}"
request_url += f"&suppressNotifications={boolstr(supress_notifications)}"
request_url += f"&api-version=4.1"
request_url += "&api-version=4.1"
response = self.http_client.post(
request_url,
@ -430,7 +431,7 @@ class ADOWorkItemsClient(ADOBaseClient):
)
request_url += f"?bypassRules={boolstr(bypass_rules)}"
request_url += f"&suppressNotifications={boolstr(supress_notifications)}"
request_url += f"&api-version=4.1"
request_url += "&api-version=4.1"
response = self.http_client.patch(
request_url,
@ -489,7 +490,7 @@ class ADOWorkItemsClient(ADOBaseClient):
)
request_url += f"?suppressNotifications={boolstr(supress_notifications)}"
request_url += f"&destroy={boolstr(permanent)}"
request_url += f"&api-version=4.1"
request_url += "&api-version=4.1"
response = self.http_client.delete(
request_url, additional_headers={"Content-Type": "application/json-patch+json"}

Просмотреть файл

@ -7,7 +7,6 @@
# pylint: disable=line-too-long
import datetime
import os
import sys
import unittest
@ -49,7 +48,7 @@ class LibraryTests(unittest.TestCase):
"""Test get blob."""
diff = self.client.git.get_blob(
blob_id="7351cd0c84377c067602e97645e9c91100c38a6e",
blob_format=simple_ado.git.ADOGitClient.BlobFormat.text,
blob_format=simple_ado.git.ADOGitClient.BlobFormat.TEXT,
project_id=self.test_config.project_id,
repository_id=self.test_config.repository_id,
)
@ -145,7 +144,7 @@ class LibraryTests(unittest.TestCase):
def test_capabilities(self):
"""Test setting capabilities."""
pool = self.client.pools.get_pools(
action_filter=simple_ado.pools.TaskAgentPoolActionFilter.manage
action_filter=simple_ado.pools.TaskAgentPoolActionFilter.MANAGE
)[0]
agent = self.client.pools.get_agents(pool_id=pool["id"])[0]
capabilities = agent["userCapabilities"]