From 66b819a48b8b9d3c684f7beb09e2f5ffd8e88802 Mon Sep 17 00:00:00 2001 From: "changjun.zhu" Date: Tue, 23 Nov 2021 17:26:22 +0800 Subject: [PATCH] feat(client): design structure and interfaces of squashAndMergeJob --- tensorbay/client/job.py | 14 ++++++ tensorbay/client/version.py | 89 +++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/tensorbay/client/job.py b/tensorbay/client/job.py index 706f79f26..a24b9f76e 100644 --- a/tensorbay/client/job.py +++ b/tensorbay/client/job.py @@ -7,6 +7,7 @@ from typing import Any, Dict, Optional, Tuple, Type, TypeVar +from tensorbay.client.struct import Draft from tensorbay.utility import AttrsMixin, ReprMixin, ReprType, attr, camel, common_loads @@ -118,3 +119,16 @@ def update(self, until_complete: bool = False) -> None: until_complete: Whether to update job information until it is complete. """ + + +class SquashAndMergeJob(Job): + """This class defines :class:`SquashAndMergeJob`.""" + + @property + def result(self) -> Draft: + """Get the result of the SquashAndMergeJob. + + Return: + The draft obtained from SquashAndMergeJob. + + """ diff --git a/tensorbay/client/version.py b/tensorbay/client/version.py index cf7d8c222..bb29b8c2d 100644 --- a/tensorbay/client/version.py +++ b/tensorbay/client/version.py @@ -7,6 +7,7 @@ from typing import Any, Dict, Generator, Optional, Union +from tensorbay.client.job import SquashAndMergeJob from tensorbay.client.lazy import PagingList from tensorbay.client.requests import Client from tensorbay.client.status import Status @@ -659,3 +660,91 @@ def _generate_jobs( The generator of job info. """ + + def create_squash_and_merge_job( + self, + title: str = "", + description: str = "", + *, + draft_title: str, + source_branch_name: str, + target_branch_name: Optional[str] = None, + draft_description: str = "", + strategy: Optional[str] = "abort", + ) -> SquashAndMergeJob: + """Create a :class:`SquashAndMergeJob`. + + Squash commits in source branch, then merge into target branch by creating a new draft. + If the target branch name is not given, the draft will be based on the branch name stored + in the dataset client. And during merging, the conflicts between branches can be resolved + in three different strategies: "abort", "override" and "skip". + + Arguments: + title: The SquashAndMergeJob title. + description: The SquashAndMergeJob description. + draft_title: The draft title. + source_branch_name: The name of the branch to be squashed. + target_branch_name: The target branch name of the merge operation. + draft_description: The draft description. + strategy: The strategy of handling the branch conflict. There are three options: + + 1. "abort": abort the opetation; + 2. "override": the squashed branch will override the target branch; + 3. "skip": keep the origin branch. + + Raises:# flake8: noqa: F402 + StatusError: When squashing and merging without basing on a branch. + + Return: + The SquashAndMergeJob. + + """ + + def get_squash_and_merge_job(self, job_id: str) -> SquashAndMergeJob: + """Get a :class:`SquashAndMergeJob`. + + Arguments: + job_id: The SquashAndMergeJob id. + + Return: + The SquashAndMergeJob. + + """ + + def list_squash_and_merge_jobs( + self, status: Optional[str] = None + ) -> PagingList[SquashAndMergeJob]: + """List the SquashAndMergeJob. + + Arguments: + status: The SquashAndMergeJob status which includes "QUEUING", "PROCESSING", "SUCCESS", + "FAIL", "ABORT" and None. None means all kinds of status. + + Return: + The PagingList of SquashAndMergeJob. + + """ + + def abort_squash_and_merge_job(self, job_id: str) -> None: + """Abort a :class:`SquashAndMergeJob`. + + Arguments: + job_id: The SquashAndMergeJob id. + + """ + + def retry_squash_and_merge_job(self, job_id: str) -> None: + """Retry a :class:`SquashAndMergeJob`. + + Arguments: + job_id: The SquashAndMergeJob id. + + """ + + def delete_squash_and_merge_job(self, job_id: str) -> None: + """Delete a :class:`SquashAndMergeJob`. + + Arguments: + job_id: The SquashAndMergeJob id. + + """