Git API - Freestyle Docs
Git API
Read and modify repository data through Freestyle Git APIs.
Use the Git API when your application needs repository data without cloning locally.
Get File Or Directory Contents
import { freestyle } from "freestyle";
const repo = freestyle.git.repos.ref({
repoId: "your-repo-id",
});
const file = await repo.contents.get({
path: "src/index.ts",
rev: "main",
});
console.log(file);
Directory responses include nested entries:
const dir = await repo.contents.get({
path: "src",
rev: "main",
});
console.log(dir);
Download Archives
import { writeFile } from "node:fs/promises";
const tarball = await repo.contents.downloadTarball({ rev: "main" });
await writeFile("repo.tar", Buffer.from(tarball));
const zip = await repo.contents.downloadZip({ rev: "main" });
await writeFile("repo.zip", Buffer.from(zip));
Branches
const branch = await repo.branches.get({ branchName: "main" });
console.log(branch.sha);
const branches = await repo.branches.list();
console.log(branches);
Create a branch:
await repo.branches.create({
name: "feature/new-flow",
});
await repo.branches.create({
name: "feature/from-commit",
sha: "a1b2c3d4e5f6",
});
Set the default branch:
await repo.branches.setDefaultBranch({
defaultBranch: "main",
});
Commits
List commits:
const commits = await repo.commits.list();
console.log(commits);
Create a commit by writing file changes:
await repo.commits.create({
branch: "main",
message: "Update README",
files: [{ path: "README.md", content: "# Updated README\n" }],
});
Tags
const tags = await repo.tags.list();
const tag = await repo.tags.get({
tagName: "v1.0.0",
});
console.log(tag);