private key and make note of your organization’s
name identifier.
-
Install the SDK:
CopyAsk AI
pnpm i @pierre/storage -
Initialize the client:
CopyAsk AI
import { GitStorage } from '@pierre/storage'; const store = new GitStorage({ name: 'your-org', // Your organization identifier key: env.privateKey, // Your API key }); -
Create and use a repository:
CopyAsk AI
// Create a new repository const repo = await store.createRepo(); // Get a secure Git URL with authentication const url = await repo.getRemoteURL(); // Configure Git to use the repository console.log(`git remote add origin ${url}`); // Output: git remote add origin https://t:JWT@[org].code.storage/repo-id.git -
Make your first commit:
CopyAsk AI
import { GitStorage } from '@pierre/storage'; async function main() { const store = new GitStorage({ name: 'your-name', key: env.privateKey, }); const repo = await store.createRepo(); console.log(`Created repository: ${repo.id}`); const url = await repo.getRemoteURL(); console.log(`Git URL: ${url}`); const result = await repo .createCommit({ targetBranch: 'main', commitMessage: 'Initial commit', author: { name: 'Your Name', email: 'you@example.com' }, }) .addFileFromString('README.md', '# My Project\n\nWelcome!') .send(); console.log(`Commit SHA: ${result.commitSha}`); } -
Read repository data:
CopyAsk AI
async function readData() { const store = new GitStorage({ name: 'your-name', key: env.privateKey }); const repo = await store.findOne({ id: 'repo-id' }); if (!repo) return; // List files const files = await repo.listFiles(); console.log('Files:', files.paths); // List commits const commits = await repo.listCommits({ limit: 10 }); commits.commits.forEach((commit) => { console.log(`${commit.sha.slice(0, 7)} - ${commit.message}`); }); // Get file content const response = await repo.getFileStream({ path: 'README.md' }); const content = await response.text(); console.log(content); } -
Apply an existing diff:
CopyAsk AI
async function applyDiff() { const store = new GitStorage({ name: 'your-name', key: env.privateKey }); const repo = await store.findOne({ id: 'repo-id' }); if (!repo) return; const diffText = `--- a/README.md +++ b/README.md @@ -Old line +New line `; const result = await repo.createCommitFromDiff({ targetBranch: 'main', commitMessage: 'Apply upstream changes', diff: diffText, author: { name: 'Automation', email: 'bot@example.com' }, baseBranch: 'main', // optional, matches createCommit options }); console.log(`Updated commit: ${result.commitSha}`); }