SDK
Markdown

TypeScript SDK 0.1.10

Git

Every sandbox contains a Git repository. Use the SDK to review changes, create checkpoints, work with branches, synchronize a provider repository, or clone the sandbox elsewhere.

Review changes

TypeScript
const review = await sandbox.git.review();

console.log(review.files);
console.log(review.stagedPatch);
console.log(review.unstagedPatch);

review() returns the changed files and their staged and unstaged patches, making it suitable for a review interface or automated validation.

Create a checkpoint

TypeScript
await sandbox.git.stage({
  paths: ['app/Http/Controllers/InventoryController.php'],
});

const checkpoint = await sandbox.git.checkpoint(
  'PHPSandbox <[email protected]>',
  'Add inventory endpoint',
  'main',
);

Use unstage() to remove paths from the index. revert() discards selected changes, so use it only after reviewing the affected paths.

Work with branches

TypeScript
await sandbox.git.checkout('feature/inventory', true);

const status = await sandbox.git.status();
const history = await sandbox.git.log(status.branch);

The second argument to checkout() creates the branch when it does not exist.

Synchronize with GitHub

First link a GitHub integration and attach it to the sandbox. Then create a Git target:

TypeScript
const target = await sandbox.git.targets.create({
  provider: 'github',
  repository: 'acme/inventory',
  branch: 'main',
  author: {
    name: 'PHPSandbox',
    email: '[email protected]',
  },
  setDefault: true,
});

await target.sync({ direction: 'both' });

Use pull, push, or both for the synchronization direction. The target retains the repository and branch configuration; the attached integration supplies authorization when synchronization runs.

Clone a sandbox repository

TypeScript
const credentials = await sandbox.git.credentials();

Use the returned URL, username, and password with a standard Git client. The credentials are short-lived: do not place them in source control, command history, logs, or a permanent remote URL.

Cloning creates another working copy of the repository. Use Managing sandboxes when you need another sandbox with its own environment.

Loading templates

You can also reach out on Twitter or Discord if you need help.