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

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

Already on GitHub?Sign in to your account

Merged

Conversation

tommaso-moro
Copy link
Contributor

@tommaso-morotommaso-moro commentedAug 11, 2025
edited
Loading

Closes:#728

Overview

This PR significantly improves how we handle refs in theget_file_contents tool, after usersreported the tool being often broken from bad ref handling.

The problem

Despite the tool description, models can pass as argument to the tool aref formatted either as fully qualified (e.g.refs/heads/beanch_name) or as short user-friendly names (e.g.branch_name).

Theget_repository_content endpoint from the Github API is able to handle both flexibly:
Screenshot 2025-08-11 at 11 47 24
Screenshot 2025-08-11 at 11 47 39

However, theget_reference endpoint doesn't (it requires aref formatted in a specific way):
Screenshot 2025-08-11 at 11 51 42
Screenshot 2025-08-11 at 11 51 33

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 aref by identifying the format in which it was provided and constructing a fully qualifiedref accordingly. In short, the newresolveGitReference function now handles:

  • Fully-Qualified refs:refs/heads/main
  • Partially-Qualified refs:heads/main
  • Short Name refs:main (discovering automatically if it's a branch or a tag)

This ensures that the tool can handle the most common ways in which theref input is provided by the user.

Additionally, I added:

  • Comprehensive tests that cover all new logic paths.
  • I have added quite detailed comments to the function itself to make the resolution logic, which can be tedious, much easier to follow

Demo
Screenshot 2025-08-11 at 11 43 38
Screenshot 2025-08-11 at 11 39 53
Screenshot 2025-08-07 at 17 55 20

@tommaso-morotommaso-moro changed the titleTommy/improve ref handlingTommy/improve-ref-handlingAug 11, 2025
@tommaso-morotommaso-moro marked this pull request as ready for reviewAugust 11, 2025 11:02
@tommaso-morotommaso-moro requested a review froma team as acode ownerAugust 11, 2025 11:02
@CopilotCopilotAI review requested due to automatic review settingsAugust 11, 2025 11:02
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 significantly improves the ref handling in theget_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:

  • EnhancedresolveGitReference 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.

FileDescription
pkg/github/repositories.goEnhancedresolveGitReference function with improved ref resolution logic and detailed documentation
pkg/github/repositories_test.goAdded comprehensive test cases covering all ref format scenarios and error conditions

Copy link
Contributor

@almaleksiaalmaleksia left a 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.

@tommaso-morotommaso-moro merged commit0b80f68 intogithub:mainAug 11, 2025
10 checks passed
nickytonline pushed a commit to nickytonline/github-mcp-http that referenced this pull requestOct 4, 2025
* make resolveGitReference function more robust, add comments to follow the logic* add  tests for new functionality* lint fix 1* fix linting by using inverted if instead of empty if block* remove unused var* refactor* remove comment* small fix* add ref == "" case in switch statement, use originalRef instead of ref in case definitions and some of the logic
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@almaleksiaalmaleksiaalmaleksia approved these changes

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

Successfully merging this pull request may close these issues.

MCP server not getting Permissions even they were given (for Organization)
2 participants
@tommaso-moro@almaleksia

[8]ページ先頭

©2009-2025 Movatter.jp