Manage Repositories
Create, list, delete repositories and set up authentication.
Creating a Repository
Empty Repository
Calling create in the git.repos namespace will create a new empty git
repository.
import { freestyle } from "freestyle";
const { repo } = await freestyle.git.repos.create();From a Source
You can fork an existing repository and all its history by providing the URL and branch.
await freestyle.git.repos.create({
source: {
url: "https://github.com/user/repo.git",
}
});Import Content
You can import a repository's files directly without any history. Raw files,
tar urls, and zip urls are also supported types under import.
Imports require a commit message to be provided for the initial commit.
await freestyle.git.repos.create({
import: {
type: "git",
commitMessage: "import from git",
url: "https://github.com/user/repo.git",
},
});Listing Repositories
List all repositories in your project with optional pagination.
import { freestyle } from "freestyle";
const result = await freestyle.git.repos.list({
limit: 20,
cursor: 0,
});
console.log(`Total repositories: ${result.total}`);
for (const repo of result.repositories) {
console.log(`${repo.id} — created ${repo.created_at}`);
}Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | number | — | Maximum number of repositories to return |
cursor | number | 0 | Offset for pagination |
Response:
| Field | Type | Description |
|---|---|---|
repositories | Array | List of repository objects |
total | number | Total number of repositories |
offset | number | Current pagination offset |
Deleting a Repository
Permanently delete a repository and all its data.
import { freestyle } from "freestyle";
await freestyle.git.repos.delete({
repoId: "your-repo-id",
});Authentication & Cloning
By default git repositories are private. To clone one, you'll need to create a freestyle identity and access token.
const { identity } = await freestyle.identities.create();
await identity.permissions.git.grant({
permission: "write",
repoId: repoId,
});
const { token } = await identity.tokens.create();
console.log(`git clone https://x-access-token:${token}@git.freestyle.sh/${repoId}`);You can also use bearer auth and your freestyle api key to clone a repository. This is mostly useful for testing.
git -c http.extraHeader="Authorization: Bearer <your-api-key>" clone https://git.freestyle.sh/<repo-id>Public repositories can be cloned without authentication, but you'll still need authentication to push changes.
await freestyle.git.repos.create({
public: true,
});