-
Notifications
You must be signed in to change notification settings - Fork 2k
Tommy/improve-ref-handling #851
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
Tommy/improve-ref-handling #851
Conversation
There was a problem hiding this 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 significantly improves the ref handling in the get_file_contents
tool to better handle different ref formats that models commonly provide. The issue was that while the GitHub API's content endpoint can handle both fully-qualified refs (refs/heads/branch_name
) and short names (branch_name
), the reference endpoint requires fully-qualified refs, causing the tool to fail frequently.
Key changes:
- Enhanced
resolveGitReference
function with robust logic to handle fully-qualified, partially-qualified, and short name refs - Added comprehensive test coverage for all ref resolution scenarios
- Improved error handling and logging for better diagnostics
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
pkg/github/repositories.go | Enhanced resolveGitReference function with improved ref resolution logic and detailed documentation |
pkg/github/repositories_test.go | Added comprehensive test cases covering all ref format scenarios and error conditions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this logic!
Left some comments, mostly flow and readability related.
…f in case definitions and some of the logic
Closes: #728
Overview
This PR significantly improves how we handle refs in the
get_file_contents
tool, after users reported the tool being often broken from bad ref handling.The problem
Despite the tool description, models can pass as argument to the tool a
ref
formatted either as fully qualified (e.g.refs/heads/beanch_name
) or as short user-friendly names (e.g.branch_name
).The get_repository_content endpoint from the Github API is able to handle both flexibly:


However, the


get_reference
endpoint doesn't (it requires aref
formatted in a specific way):Our previous logic would fail often because it uses both endpoints but it was not handling user-friendly refs (e.g.
branch_name
,heads/branch_name
,tag_name
), which are often provided by models to the tool. This would thus break the tool.The Solution
This PR introduces new, robust logic to resolve a
ref
by identifying the format in which it was provided and constructing a fully qualifiedref
accordingly. In short, the newresolveGitReference
function now handles:refs/heads/main
heads/main
main
(discovering automatically if it's a branch or a tag)This ensures that the tool can handle the most common ways in which the
ref
input is provided by the user.Additionally, I added:
Demo


