Skip to content

Commit

Permalink
Fix view_file tool for external repos and remove process.env.GITHUB_T…
Browse files Browse the repository at this point in the history
…OKEN usage (#91)

* No changes detected; commit message unnecessary.

* No changes detected between old and new content in view-file.ts.

* No changes detected in `view-file.ts`. Commit discarded.

* No changes detected in view-file.ts; commit skipped.

* No changes detected in view-file.ts, commit unnecessary.
  • Loading branch information
AtlantisPleb authored Aug 28, 2024
1 parent 3239985 commit c39116f
Showing 1 changed file with 17 additions and 8 deletions.
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

0 comments on commit c39116f

Please sign in to comment.