Squash and Merge#

TensorBay supports squashing and merging between different branches asynchronously.

Firstly, a dataset client instance with commits on different branches is needed. See more details in Draft and Commit.

../../_images/squash_and_merge.png

Fig. 10 The graphical gas log about the squash and merge operation below.#

from tensorbay import GAS

# Please visit `https://gas.graviti.com/tensorbay/developer` to get the AccessKey.
gas = GAS("<YOUR_ACCESSKEY>")
dataset_client = gas.create_dataset("<DATASET_NAME>")

dataset_client.create_draft("draft-1")
dataset_client.commit("commit-1")

dataset_client.create_branch("dev")
dataset_client.create_draft("draft-2")
dataset_client.commit("commit-2")

dataset_client.create_draft("draft-3")
dataset_client.commit("commit-3")

dataset_client.checkout("main")
dataset_client.create_draft("draft-4")
dataset_client.commit("commit-4")

SquashAndMergeJob#

TensorBay SDK allows create, get, list or delete SquashAndMergeJob via SquashAndMerge.

Create#

In the case of creating a SquashAndMergeJob, the target_branch_name could be given in advance:

job = dataset_client.squash_and_merge.create_job(
    draft_title="draft-5",
    source_branch_name="dev",
    target_branch_name="main",
    draft_description="draft_description",
    strategy="override",
)

Or checkout to the target_branch first. In this case, the current branch is main, so we can create job directly.

job = dataset_client.squash_and_merge.create_job(
    draft_title="draft-5",
    source_branch_name="dev",
    draft_description="draft_description",
    strategy="override",
)

Note

There are three strategies for handling the branch conflict:

  1. “abort”: abort the opetation;

  2. “override”: the squashed branch will override the target branch;

  3. “skip”: keep the origin branch.

Get, list or delete#

The latest SquashAndMergeJob can be obtained by get_job() or list_jobs(). The finished SquashAndMergeJob can be deleted by delete_job().

job = dataset_client.squash_and_merge.get_job("jobId")
dataset_client.squash_and_merge.delete_job("jobId")
job = dataset_client.squash_and_merge.list_jobs()[0]

Get information#

Available SquashAndMergeJob information includes title, description, job_id, arguments, created_at, started_at, finished_at, status, error_message and result.

job.status
job.result
job.error_message
job.arguments

Note

If the SquashAndMergeJob is successfully completed, the result will be a Draft.

Update#

The latest information of a SquashAndMergeJob can be obtained after update(). Note that if the until_complete is set to True, the SquashAndMergeJob will be blocked until it is completed.

job.update()
job.update(until_complete=True)

Abort or retry#

SquashAndMergeJob also supports abort() and retry():

job.abort()
job.retry()