Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix view_file tool for external repos and remove process.env.GITHUB_TOKEN usage #91

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions tools/view-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,32 @@ export const viewFileTool = (context: ToolContext): CoreTool<typeof params, Resu
description: "View file contents at path",
parameters: params,
execute: async ({ path, owner, repo, branch }: Params): Promise<Result> => {
if (!context.repo || !context.user) {
const repoOwner = owner || context.repo?.owner;
const repoName = repo || context.repo?.name;
const repoBranch = branch || context.repo?.branch || 'main';

if (!repoOwner || !repoName) {
return {
success: false,
error: "Missing repository or user information",
summary: "Failed to view file due to missing context",
details: "The tool context is missing required repository or user information."
error: "Missing repository information",
summary: "Failed to view file due to missing repository information",
details: "The repository owner or name is missing. Please provide both in the request or ensure they are set in the context."
};
}

const repoOwner = owner || context.repo.owner;
const repoName = repo || context.repo.name;
const repoBranch = branch || context.repo.branch || 'main';
if (!context.gitHubToken) {
return {
success: false,
error: "Missing GitHub token",
summary: "Failed to view file due to missing GitHub token",
details: "The GitHub token is missing. Please ensure it is provided in the context."
};
}

try {
const content = await githubReadFile({
path,
token: context.gitHubToken ?? process.env.GITHUB_TOKEN ?? '', // TODO
token: context.gitHubToken,
repoOwner,
repoName,
branch: repoBranch
Expand Down
Loading