Freestyle Git search lets your product inspect code without cloning a repository.
Content Search
Search file contents at a branch, tag, or commit.
import { freestyle } from "freestyle";
const repo = freestyle.git.repos.ref({ repoId: "your-repo-id" });
const result = await repo.search({
query: "TODO",
rev: "main",
pathPattern: "src/**/\*.ts",
excludePattern: "**/\*.test.ts"
});
for (const file of result.files) {
for (const match of file.matches) {
console.log(`${file.path}:${match.lineNumber} ${match.line}`);
}
}
curl "https://api.freestyle.sh/git/v1/repo/${REPO_ID}/search?query=TODO&pathPattern=src/**/*.ts" \
-H "Authorization: Bearer ${FREESTYLE_API_KEY}" Use regex patterns when you need structural matches:
const result = await repo.search({
query: "^(export\\s+)?(async\\s+)?function\\s+\\w+",
isRegex: true,
pathPattern: "**/*.ts",
});
Filename Search
const result = await repo.searchFiles({
query: "index",
maxResults: 20,
});
for (const file of result.files) {
console.log(file.path);
}
Commit Message Search
const result = await repo.searchCommits({
query: "fix",
maxResults: 10,
});
for (const commit of result.commits) {
console.log(`${commit.sha.slice(0, 7)} ${commit.message}`);
}
Diff Search
Use diff search when you need to find when text was added or changed.
const result = await repo.searchDiffs({
query: "deprecatedMethod",
maxResults: 20,
});
for (const match of result.matches) {
console.log(match.commitSha, match.filePath);
}
Pagination
Use maxResults, offset, and hasMore to page through large result sets.
let offset = 0;
const files = [];
while (true) {
const result = await repo.search({
query: "TODO",
maxResults: 50,
offset,
});
files.push(...result.files);
if (!result.hasMore) break;
offset += 50;
}