Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add include_sha parameter to get_file_contents tool#605

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
yonaka15 wants to merge6 commits intogithub:main
base:main
Choose a base branch
Loading
fromyonaka15:feature/refine-get-file-contents-v8

Conversation

yonaka15
Copy link

Summary

This PR addresses issue#595 by adding an optionalinclude_sha parameter to theget_file_contents tool, providing a more flexible and performant solution than the previous approach in PR#599.

Problem

Theget_file_contents tool was missing the SHA hash in its response, which is essential for subsequent file update operations usingcreate_or_update_file. The SHA is required by the GitHub API for any update operation.

Solution

Instead of always returning metadata (as in PR#599), this PR adds aninclude_sha boolean parameter that allows users to explicitly choose between:

  • Raw content (default): Fast retrieval via GitHub's Raw API
  • File metadata: Complete file information including SHA, size, type via Contents API

Key Features

  • Backward compatible: Default behavior unchanged
  • Performance optimized: Raw API used when metadata not needed
  • Flexible: Works for both files and directories
  • Comprehensive: Returns complete GitHub API metadata when requested
  • Well-tested: Full test coverage for all scenarios

Usage Examples

// Get file content (existing behavior)get_file_contents({owner:"user",repo:"repo",path:"file.md"})// Returns: raw file content// Get file metadata including SHAget_file_contents({owner:"user",repo:"repo",path:"file.md",include_sha:true})// Returns: { name, path, sha, size, type, content, encoding, ... }

Changes Made

  • Addedinclude_sha boolean parameter to tool schema
  • Updated implementation to conditionally use Contents API vs Raw API
  • Enhanced tool description to document new parameter
  • Added comprehensive test coverage for all scenarios
  • Updated tool snapshots to reflect schema changes

Testing

  • ✅ All existing tests pass
  • ✅ New test cases cover include_sha functionality
  • ✅ Edge cases and error scenarios tested
  • ✅ Both file and directory metadata retrieval verified

Supersedes

This PR supersedes#599 by providing a more user-friendly and performant solution to the same problem.

Closes#595
Supersedes#599

- Add include_sha boolean parameter to control metadata vs raw content retrieval- When include_sha=true, always use GitHub Contents API to ensure SHA is returned- When include_sha=false (default), maintain existing behavior with raw content preference- Unify GitHub API processing to handle both files and directories consistently- Improve error handling and fallback logic for better reliability- Update tool description and parameter documentation- Update toolsnap test file to reflect new parameterThis enhancement allows users to reliably obtain file metadata (SHA, size, type)regardless of file size, while maintaining backward compatibility with existing clients.
Add optional boolean parameter to retrieve file metadata instead of raw content.When include_sha=true, returns SHA, size, and other metadata via GitHub Contents API.Maintains backward compatibility and performance with Raw API as default.- Add include_sha parameter with comprehensive test coverage- Support metadata retrieval for both files and directories- Update tool description and schema validation
@CopilotCopilotAI review requested due to automatic review settingsJune 28, 2025 23:59
@yonaka15yonaka15 requested a review froma team as acode ownerJune 28, 2025 23:59
Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull Request Overview

This PR adds an optional include_sha parameter to the get_file_contents tool, allowing users to choose between fast raw content retrieval and detailed file metadata (including SHA) needed for file update operations.

  • Introduce the include_sha boolean parameter to the tool schema and update its description.
  • Modify the API call logic to conditionally use either the raw content or the GitHub Contents API based on the include_sha value.
  • Update tests and snapshots to cover the new include_sha functionality.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

FileDescription
pkg/github/repositories_test.goAdded schema check for include_sha and new test cases for both metadata and raw content fetching.
pkg/github/repositories.goExtended tool description, added the include_sha parameter, and updated API call flow and error handling accordingly.
pkg/github/toolsnaps/get_file_contents.snapUpdated snapshot description and schema to include the new include_sha parameter.
Comments suppressed due to low confidence (1)

pkg/github/repositories.go:529

  • [nitpick] Consider adding an inline comment explaining why the raw content API call is skipped when include_sha is true, to improve future maintainability and clarity.
if !includeSha && path != "" && !strings.HasSuffix(path, "/") {

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Toolget_file_contents is missing the requiredsha in its response
1 participant
@yonaka15

[8]ページ先頭

©2009-2025 Movatter.jp