Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9680b24

Browse files
committed
comment cleanup, function rename and some more tests
1 parent 2fdda7c commit 9680b24

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

pkg/github/repository_resource.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,53 @@ import (
1313
"github.com/mark3labs/mcp-go/server"
1414
)
1515

16-
// getRepositoryContent defines the resource template and handler for the Repository Content API.
17-
func getRepositoryContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
16+
// getRepositoryResourceContent defines the resource template and handler for getting repository content.
17+
func getRepositoryResourceContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
1818
return mcp.NewResourceTemplate(
1919
"repo://{owner}/{repo}/contents{/path*}", // Resource template
2020
t("RESOURCE_REPOSITORY_CONTENT_DESCRIPTION", "Repository Content"),
2121
),
22-
repoContentsResourceHandler(client)
22+
repositoryResourceContentsHandler(client)
2323
}
2424

25-
// getRepositoryContent defines the resource template and handler for the Repository Content API.
26-
func getRepositoryBranchContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
25+
// getRepositoryContent defines the resource template and handler for getting repository content for a branch.
26+
func getRepositoryResourceBranchContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
2727
return mcp.NewResourceTemplate(
2828
"repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}", // Resource template
2929
t("RESOURCE_REPOSITORY_CONTENT_BRANCH_DESCRIPTION", "Repository Content for specific branch"),
3030
),
31-
repoContentsResourceHandler(client)
31+
repositoryResourceContentsHandler(client)
3232
}
3333

34-
// getRepositoryContent defines the resource template and handler for the Repository Content API.
35-
func getRepositoryCommitContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
34+
// getRepositoryResourceCommitContent defines the resource template and handler for getting repository content for a commit.
35+
func getRepositoryResourceCommitContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
3636
return mcp.NewResourceTemplate(
3737
"repo://{owner}/{repo}/sha/{sha}/contents{/path*}", // Resource template
3838
t("RESOURCE_REPOSITORY_CONTENT_COMMIT_DESCRIPTION", "Repository Content for specific commit"),
3939
),
40-
repoContentsResourceHandler(client)
40+
repositoryResourceContentsHandler(client)
4141
}
4242

43-
// getRepositoryContent defines the resource template and handler for the Repository Content API.
44-
func getRepositoryTagContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
43+
// getRepositoryResourceTagContent defines the resource template and handler for getting repository content for a tag.
44+
func getRepositoryResourceTagContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
4545
return mcp.NewResourceTemplate(
4646
"repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", // Resource template
4747
t("RESOURCE_REPOSITORY_CONTENT_TAG_DESCRIPTION", "Repository Content for specific tag"),
4848
),
49-
repoContentsResourceHandler(client)
49+
repositoryResourceContentsHandler(client)
5050
}
5151

52-
// getRepositoryContent defines the resource template and handler for the Repository Content API.
53-
func getRepositoryPrContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
52+
// getRepositoryResourcePrContent defines the resource template and handler for getting repository content for a pull request.
53+
func getRepositoryResourcePrContent(client *github.Client, t translations.TranslationHelperFunc) (mcp.ResourceTemplate, server.ResourceTemplateHandlerFunc) {
5454
return mcp.NewResourceTemplate(
5555
"repo://{owner}/{repo}/refs/pull/{pr_number}/head/contents{/path*}", // Resource template
5656
t("RESOURCE_REPOSITORY_CONTENT_PR_DESCRIPTION", "Repository Content for specific pull request"),
5757
),
58-
repoContentsResourceHandler(client)
58+
repositoryResourceContentsHandler(client)
5959
}
6060

61-
func repoContentsResourceHandler(client *github.Client) func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
62-
return func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) { // Extract parameters from request.Params.URI
61+
func repositoryResourceContentsHandler(client *github.Client) func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
62+
return func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
6363

6464
owner := request.Params.Arguments["owner"].([]string)[0]
6565
repo := request.Params.Arguments["repo"].([]string)[0]

pkg/github/repository_resource_test.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import (
66
"net/http"
77
"testing"
88

9+
"github.com/github/github-mcp-server/pkg/translations"
910
"github.com/google/go-github/v69/github"
1011
"github.com/mark3labs/mcp-go/mcp"
1112
"github.com/migueleliasweb/go-github-mock/src/mock"
1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
1415
)
1516

16-
func Test_RepoContentsResourceHandler(t *testing.T) {
17+
func Test_repositoryResourceContentsHandler(t *testing.T) {
1718
mockDirContent := []*github.RepositoryContent{
1819
{
1920
Type: github.Ptr("file"),
@@ -143,7 +144,7 @@ func Test_RepoContentsResourceHandler(t *testing.T) {
143144
for _, tc := range tests {
144145
t.Run(tc.name, func(t *testing.T) {
145146
client := github.NewClient(tc.mockedClient)
146-
handler := repoContentsResourceHandler(client)
147+
handler := repositoryResourceContentsHandler(client)
147148

148149
request := mcp.ReadResourceRequest{
149150
Params: struct {
@@ -167,3 +168,27 @@ func Test_RepoContentsResourceHandler(t *testing.T) {
167168
})
168169
}
169170
}
171+
172+
func Test_getRepositoryResourceContent(t *testing.T) {
173+
tmpl, _ := getRepositoryResourceContent(nil, translations.NullTranslationHelper)
174+
require.Equal(t, "repo://{owner}/{repo}/contents{/path*}", tmpl.URITemplate.Raw())
175+
}
176+
177+
func Test_getRepositoryResourceBranchContent(t *testing.T) {
178+
tmpl, _ := getRepositoryResourceBranchContent(nil, translations.NullTranslationHelper)
179+
require.Equal(t, "repo://{owner}/{repo}/refs/heads/{branch}/contents{/path*}", tmpl.URITemplate.Raw())
180+
}
181+
func Test_getRepositoryResourceCommitContent(t *testing.T) {
182+
tmpl, _ := getRepositoryResourceCommitContent(nil, translations.NullTranslationHelper)
183+
require.Equal(t, "repo://{owner}/{repo}/sha/{sha}/contents{/path*}", tmpl.URITemplate.Raw())
184+
}
185+
186+
func Test_getRepositoryResourceTagContent(t *testing.T) {
187+
tmpl, _ := getRepositoryResourceTagContent(nil, translations.NullTranslationHelper)
188+
require.Equal(t, "repo://{owner}/{repo}/refs/tags/{tag}/contents{/path*}", tmpl.URITemplate.Raw())
189+
}
190+
191+
func Test_getRepositoryResourcePrContent(t *testing.T) {
192+
tmpl, _ := getRepositoryResourcePrContent(nil, translations.NullTranslationHelper)
193+
require.Equal(t, "repo://{owner}/{repo}/refs/pull/{pr_number}/head/contents{/path*}", tmpl.URITemplate.Raw())
194+
}

pkg/github/server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ func NewServer(client *github.Client, readOnly bool, t translations.TranslationH
2525
server.WithLogging())
2626

2727
// Add GitHub Resources
28-
s.AddResourceTemplate(getRepositoryContent(client, t))
29-
s.AddResourceTemplate(getRepositoryBranchContent(client, t))
30-
s.AddResourceTemplate(getRepositoryCommitContent(client, t))
31-
s.AddResourceTemplate(getRepositoryTagContent(client, t))
32-
s.AddResourceTemplate(getRepositoryPrContent(client, t))
28+
s.AddResourceTemplate(getRepositoryResourceContent(client, t))
29+
s.AddResourceTemplate(getRepositoryResourceBranchContent(client, t))
30+
s.AddResourceTemplate(getRepositoryResourceCommitContent(client, t))
31+
s.AddResourceTemplate(getRepositoryResourceTagContent(client, t))
32+
s.AddResourceTemplate(getRepositoryResourcePrContent(client, t))
3333

3434
// Add GitHub tools - Issues
3535
s.AddTool(getIssue(client, t))

0 commit comments

Comments
 (0)