Skip to content

Commit

Permalink
feat(client): design structure and interfaces of squashAndMergeJob
Browse files Browse the repository at this point in the history
  • Loading branch information
graczhual committed Dec 15, 2021
1 parent 0b84bae commit 66b819a
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tensorbay/client/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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.
"""
89 changes: 89 additions & 0 deletions tensorbay/client/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""

0 comments on commit 66b819a

Please sign in to comment.