- Notifications
You must be signed in to change notification settings - Fork937
Add ability to view branches for a repo #141#205
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
10 commits Select commitHold shift + click to select a range
69e37b5
Add ability to view branches for a repo #141
aryasoni98f8ff466
Update ListBranches to use GetClientFn and resolve merge conflicts
aryasoni98629922e
fix: update ListBranches test to use InputSchema and correct translat…
aryasoni9864cde12
fix: update ListBranches test to use InputSchema and correct translat…
aryasoni98b274df9
fix: update ListBranches test to handle errors in tool result
aryasoni9899060d7
fix: replace deprecated github.String with github.Ptr
aryasoni98ff13c14
Merge branch 'main' into issues-141
aryasoni983e52cc6
Merge branch 'main' of github.com:aryasoni98/github-mcp-server into i…
aryasoni98266677d
docs: add list_branches tool documentation to README
aryasoni98f04c46b
Merge branch 'issues-141' of github.com:aryasoni98/github-mcp-server …
aryasoni98File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1423,3 +1423,113 @@ func Test_PushFiles(t *testing.T) { | ||
}) | ||
} | ||
} | ||
func Test_ListBranches(t *testing.T) { | ||
aryasoni98 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// Verify tool definition once | ||
mockClient := github.NewClient(nil) | ||
tool, _ := ListBranches(stubGetClientFn(mockClient), translations.NullTranslationHelper) | ||
assert.Equal(t, "list_branches", tool.Name) | ||
assert.NotEmpty(t, tool.Description) | ||
assert.Contains(t, tool.InputSchema.Properties, "owner") | ||
assert.Contains(t, tool.InputSchema.Properties, "repo") | ||
assert.Contains(t, tool.InputSchema.Properties, "page") | ||
assert.Contains(t, tool.InputSchema.Properties, "perPage") | ||
assert.ElementsMatch(t, tool.InputSchema.Required, []string{"owner", "repo"}) | ||
// Setup mock branches for success case | ||
mockBranches := []*github.Branch{ | ||
{ | ||
Name: github.Ptr("main"), | ||
Commit: &github.RepositoryCommit{SHA: github.Ptr("abc123")}, | ||
}, | ||
{ | ||
Name: github.Ptr("develop"), | ||
Commit: &github.RepositoryCommit{SHA: github.Ptr("def456")}, | ||
}, | ||
} | ||
// Test cases | ||
tests := []struct { | ||
name string | ||
args map[string]interface{} | ||
mockResponses []mock.MockBackendOption | ||
wantErr bool | ||
errContains string | ||
}{ | ||
{ | ||
name: "success", | ||
args: map[string]interface{}{ | ||
"owner": "owner", | ||
"repo": "repo", | ||
"page": float64(2), | ||
}, | ||
mockResponses: []mock.MockBackendOption{ | ||
mock.WithRequestMatch( | ||
mock.GetReposBranchesByOwnerByRepo, | ||
mockBranches, | ||
), | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "missing owner", | ||
args: map[string]interface{}{ | ||
"repo": "repo", | ||
}, | ||
mockResponses: []mock.MockBackendOption{}, | ||
wantErr: false, | ||
errContains: "missing required parameter: owner", | ||
}, | ||
{ | ||
name: "missing repo", | ||
args: map[string]interface{}{ | ||
"owner": "owner", | ||
}, | ||
mockResponses: []mock.MockBackendOption{}, | ||
wantErr: false, | ||
errContains: "missing required parameter: repo", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Create mock client | ||
mockClient := github.NewClient(mock.NewMockedHTTPClient(tt.mockResponses...)) | ||
_, handler := ListBranches(stubGetClientFn(mockClient), translations.NullTranslationHelper) | ||
// Create request | ||
request := createMCPRequest(tt.args) | ||
// Call handler | ||
result, err := handler(context.Background(), request) | ||
if tt.wantErr { | ||
require.Error(t, err) | ||
if tt.errContains != "" { | ||
assert.Contains(t, err.Error(), tt.errContains) | ||
} | ||
return | ||
} | ||
require.NoError(t, err) | ||
require.NotNil(t, result) | ||
if tt.errContains != "" { | ||
textContent := getTextResult(t, result) | ||
assert.Contains(t, textContent.Text, tt.errContains) | ||
return | ||
} | ||
textContent := getTextResult(t, result) | ||
require.NotEmpty(t, textContent.Text) | ||
// Verify response | ||
var branches []*github.Branch | ||
err = json.Unmarshal([]byte(textContent.Text), &branches) | ||
require.NoError(t, err) | ||
assert.Len(t, branches, 2) | ||
assert.Equal(t, "main", *branches[0].Name) | ||
assert.Equal(t, "develop", *branches[1].Name) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.