Skip to content

Commit 12c2cfe

Browse files
committed
fix: close response body, improve error messages, docs
1 parent 11d8a45 commit 12c2cfe

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pkg/github/repositories.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t
501501

502502
rawOpts, err := resolveGitReference(ctx, client, owner, repo, ref, sha)
503503
if err != nil {
504-
return mcp.NewToolResultError(err.Error()), nil
504+
return mcp.NewToolResultError(fmt.Sprintf("failed to resolve git reference: %s", err)), nil
505505
}
506506

507507
// If the path is (most likely) not to be a directory, we will
@@ -592,6 +592,7 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t
592592
err,
593593
), nil
594594
}
595+
defer func() { _ = resp.Body.Close() }()
595596

596597
// Step 2: Filter tree for matching paths
597598
const maxMatchingFiles = 3
@@ -601,7 +602,7 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t
601602
if err != nil {
602603
return mcp.NewToolResultError(fmt.Sprintf("failed to marshal matching files: %s", err)), nil
603604
}
604-
return mcp.NewToolResultText(fmt.Sprintf("Provided path did not match a file or directory, but resolved ref to %s with possible path matches: %s", ref, matchingFilesJSON)), nil
605+
return mcp.NewToolResultText(fmt.Sprintf("Path did not point to a file or directory, but resolved ref to %s with possible path matches: %s", ref, matchingFilesJSON)), nil
605606
}
606607

607608
return mcp.NewToolResultError("Failed to get file contents. The path does not point to a file or directory, or the file does not exist in the repository."), nil
@@ -1328,9 +1329,9 @@ func filterPaths(entries []*github.TreeEntry, path string, maxResults int) []str
13281329
// resolveGitReference resolves git references with the following logic:
13291330
// 1. If SHA is provided, it takes precedence
13301331
// 2. If neither is provided, use the default branch as ref
1331-
// 3. Get SHA from the ref
1332+
// 3. Get commit SHA from the ref
13321333
// Refs can look like `refs/tags/{tag}`, `refs/heads/{branch}` or `refs/pull/{pr_number}/head`
1333-
// The function returns the resolved ref, SHA and any error.
1334+
// The function returns the resolved ref, commit SHA and any error.
13341335
func resolveGitReference(ctx context.Context, githubClient *github.Client, owner, repo, ref, sha string) (*raw.ContentOpts, error) {
13351336
// 1. If SHA is provided, use it directly
13361337
if sha != "" {

0 commit comments

Comments
 (0)