Applied new decorator to the code.
This commit is contained in:
69
devops.py
69
devops.py
@@ -86,7 +86,7 @@ class Organization:
|
||||
) for proj in projects_data
|
||||
]
|
||||
|
||||
@auto_properties(names=["name", "url", "description"])
|
||||
@auto_properties({"name": "name", "url": "url", "description": "description"})
|
||||
class Project:
|
||||
def __init__(self,
|
||||
org: Organization,
|
||||
@@ -142,33 +142,22 @@ class Project:
|
||||
) for repo in repos_data
|
||||
]
|
||||
|
||||
@auto_properties(names=["name", "url", "default_branch", "disabled", "in_maintenance", "remote_url", "ssh_url", "web_url"])
|
||||
@auto_properties({
|
||||
"name": "name",
|
||||
"url": "url",
|
||||
"default_branch": "defaultBranch",
|
||||
"is_disabled": "isDisabled",
|
||||
"is_in_maintenance": "isInMaintenance",
|
||||
"remote_url": "remoteUrl",
|
||||
"ssh_url": "sshUrl",
|
||||
"web_url": "webUrl"
|
||||
})
|
||||
class Repository:
|
||||
def _get(self, repo_name: str):
|
||||
r = self._project.get(f"_apis/git/repositories/{urllib.parse.quote(repo_name)}")
|
||||
json_data = r.json()
|
||||
self._id = json_data.get("id", "")
|
||||
self._name = json_data.get("name", "")
|
||||
self._url = json_data.get("url", "")
|
||||
self._default_branch = json_data.get("defaultBranch", "")
|
||||
self._is_disabled = json_data.get("isDisabled", False)
|
||||
self._is_in_maintenance = json_data.get("isInMaintenance", False)
|
||||
self._remote_url = json_data.get("remoteUrl", "")
|
||||
self._ssh_url = json_data.get("sshUrl", "")
|
||||
self._web_url = json_data.get("webUrl", "")
|
||||
self.from_json(r.json())
|
||||
|
||||
def __init__(self,
|
||||
_project: Project,
|
||||
id_or_name: str,
|
||||
name: str | None = None,
|
||||
url: str | None = None,
|
||||
default_branch: str | None = None,
|
||||
disabled: bool | None = None,
|
||||
in_maintenance: bool | None = None,
|
||||
remote_url: str | None = None,
|
||||
ssh_url: str | None = None,
|
||||
web_url: str | None = None
|
||||
):
|
||||
def __init__(self,_project: Project, id_or_name: str, **kwargs):
|
||||
|
||||
self._project = _project
|
||||
|
||||
@@ -180,17 +169,10 @@ class Repository:
|
||||
return
|
||||
|
||||
# set other properties if provided
|
||||
self._name = name if name is not None else None
|
||||
self._url = url if url is not None else None
|
||||
self._default_branch = default_branch if default_branch is not None else None
|
||||
self._is_disabled = disabled if disabled is not None else None
|
||||
self._is_in_maintenance = in_maintenance if in_maintenance is not None else None
|
||||
self._remote_url = remote_url if remote_url is not None else None
|
||||
self._ssh_url = ssh_url if ssh_url is not None else None
|
||||
self._web_url = web_url if web_url is not None else None
|
||||
self.set_auto_properties(**kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return f"Repository(name={self._name}, id={self._id})"
|
||||
return f"Repository(name={self.name}, id={self._id})"
|
||||
|
||||
def _get_path(self, path: str, params: dict = {}):
|
||||
return self._project.get(f"_apis/git/repositories/{self._id}/{path.lstrip('/')}", params=params)
|
||||
@@ -216,7 +198,7 @@ class Repository:
|
||||
) for item in items_data
|
||||
]
|
||||
|
||||
@auto_properties(names=["object_id", "git_object_type", "commit_id", "folder", "url"])
|
||||
@auto_properties({"object_id": "objectId", "git_object_type": "gitObjectType", "commit_id": "commitId", "is_folder": "isFolder", "url": "url"})
|
||||
class Item:
|
||||
def _get(self, path):
|
||||
r = self._repository._get_path(f"items/{urllib.parse.quote(path)}")
|
||||
@@ -224,21 +206,12 @@ class Item:
|
||||
for name in self.__auto_properties__:
|
||||
setattr(self, f"_{name}", r.json().get(name, None))
|
||||
|
||||
def __init__(self,
|
||||
repository: Repository,
|
||||
path: str,
|
||||
object_id: str | None = None,
|
||||
git_object_type: str | None = None,
|
||||
commit_id: str | None = None,
|
||||
is_folder: bool | None = None,
|
||||
url: str | None = None
|
||||
):
|
||||
def __init__(self, repository: Repository, path: str, **kwargs):
|
||||
|
||||
self._repository = repository
|
||||
self._path = path
|
||||
self.set_auto_properties(**kwargs) # set properties defined in decorator
|
||||
|
||||
self._object_id = object_id if object_id is not None else None
|
||||
self._git_object_type = git_object_type if git_object_type is not None else None
|
||||
self._commit_id = commit_id if commit_id is not None else None
|
||||
self._is_folder = is_folder if is_folder is not None else None
|
||||
self._url = url if url is not None else None
|
||||
@property
|
||||
def path(self):
|
||||
return self._path
|
||||
Reference in New Issue
Block a user