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

Commit1b6f0e0

Browse files
CopilotJoannaaKL
authored andcommitted
Fix wildcard path matching for raw content endpoints
Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
1 parent49e606d commit1b6f0e0

File tree

2 files changed

+48
-56
lines changed

2 files changed

+48
-56
lines changed

‎pkg/github/helper_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ const (
130130

131131
// Raw content endpoints (used for GitHub raw content API, not standard API)
132132
// These are used with the raw content client that interacts with raw.githubusercontent.com
133-
GetRawReposContentsByOwnerByRepoByPath="GET /{owner}/{repo}/HEAD/{path}"
134-
GetRawReposContentsByOwnerByRepoByBranchByPath="GET /{owner}/{repo}/refs/heads/{branch}/{path}"
135-
GetRawReposContentsByOwnerByRepoByTagByPath="GET /{owner}/{repo}/refs/tags/{tag}/{path}"
136-
GetRawReposContentsByOwnerByRepoBySHAByPath="GET /{owner}/{repo}/{sha}/{path}"
133+
GetRawReposContentsByOwnerByRepoByPath="GET /{owner}/{repo}/HEAD/{path:.*}"
134+
GetRawReposContentsByOwnerByRepoByBranchByPath="GET /{owner}/{repo}/refs/heads/{branch}/{path:.*}"
135+
GetRawReposContentsByOwnerByRepoByTagByPath="GET /{owner}/{repo}/refs/tags/{tag}/{path:.*}"
136+
GetRawReposContentsByOwnerByRepoBySHAByPath="GET /{owner}/{repo}/{sha}/{path:.*}"
137137
)
138138

139139
typeexpectationsstruct {

‎pkg/github/repository_resource_test.go‎

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ func Test_repositoryResourceContents(t *testing.T) {
3434
{
3535
name:"missing owner",
3636
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
37-
GetRawReposContentsByOwnerByRepoByPath:
38-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
39-
w.Header().Set("Content-Type","text/markdown")
40-
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
41-
require.NoError(t,err)
42-
}),
37+
GetRawReposContentsByOwnerByRepoByPath:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
38+
w.Header().Set("Content-Type","text/markdown")
39+
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
40+
require.NoError(t,err)
41+
}),
4342
}),
4443
uri:"repo:///repo/contents/README.md",
4544
handlerFn:func(depsToolDependencies) mcp.ResourceHandler {
@@ -51,12 +50,11 @@ func Test_repositoryResourceContents(t *testing.T) {
5150
{
5251
name:"missing repo",
5352
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
54-
GetRawReposContentsByOwnerByRepoByBranchByPath:
55-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
56-
w.Header().Set("Content-Type","text/markdown")
57-
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
58-
require.NoError(t,err)
59-
}),
53+
GetRawReposContentsByOwnerByRepoByBranchByPath:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
54+
w.Header().Set("Content-Type","text/markdown")
55+
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
56+
require.NoError(t,err)
57+
}),
6058
}),
6159
uri:"repo://owner//refs/heads/main/contents/README.md",
6260
handlerFn:func(depsToolDependencies) mcp.ResourceHandler {
@@ -68,12 +66,11 @@ func Test_repositoryResourceContents(t *testing.T) {
6866
{
6967
name:"successful blob content fetch",
7068
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
71-
GetRawReposContentsByOwnerByRepoByPath:
72-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
73-
w.Header().Set("Content-Type","image/png")
74-
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
75-
require.NoError(t,err)
76-
}),
69+
GetRawReposContentsByOwnerByRepoByPath:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
70+
w.Header().Set("Content-Type","image/png")
71+
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
72+
require.NoError(t,err)
73+
}),
7774
}),
7875
uri:"repo://owner/repo/contents/data.png",
7976
handlerFn:func(depsToolDependencies) mcp.ResourceHandler {
@@ -90,12 +87,11 @@ func Test_repositoryResourceContents(t *testing.T) {
9087
{
9188
name:"successful text content fetch (HEAD)",
9289
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
93-
GetRawReposContentsByOwnerByRepoByPath:
94-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
95-
w.Header().Set("Content-Type","text/markdown")
96-
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
97-
require.NoError(t,err)
98-
}),
90+
GetRawReposContentsByOwnerByRepoByPath:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
91+
w.Header().Set("Content-Type","text/markdown")
92+
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
93+
require.NoError(t,err)
94+
}),
9995
}),
10096
uri:"repo://owner/repo/contents/README.md",
10197
handlerFn:func(depsToolDependencies) mcp.ResourceHandler {
@@ -112,14 +108,13 @@ func Test_repositoryResourceContents(t *testing.T) {
112108
{
113109
name:"successful text content fetch (HEAD)",
114110
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
115-
GetRawReposContentsByOwnerByRepoByPath:
116-
http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
117-
w.Header().Set("Content-Type","text/plain")
111+
GetRawReposContentsByOwnerByRepoByPath:http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
112+
w.Header().Set("Content-Type","text/plain")
118113

119-
require.Contains(t,r.URL.Path,"pkg/github/actions.go")
120-
_,err:=w.Write([]byte("package actions\n\nfunc main() {\n // Sample Go file content\n}\n"))
121-
require.NoError(t,err)
122-
}),
114+
require.Contains(t,r.URL.Path,"pkg/github/actions.go")
115+
_,err:=w.Write([]byte("package actions\n\nfunc main() {\n // Sample Go file content\n}\n"))
116+
require.NoError(t,err)
117+
}),
123118
}),
124119
uri:"repo://owner/repo/contents/pkg/github/actions.go",
125120
handlerFn:func(depsToolDependencies) mcp.ResourceHandler {
@@ -136,12 +131,11 @@ func Test_repositoryResourceContents(t *testing.T) {
136131
{
137132
name:"successful text content fetch (branch)",
138133
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
139-
GetRawReposContentsByOwnerByRepoByBranchByPath:
140-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
141-
w.Header().Set("Content-Type","text/markdown")
142-
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
143-
require.NoError(t,err)
144-
}),
134+
GetRawReposContentsByOwnerByRepoByBranchByPath:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
135+
w.Header().Set("Content-Type","text/markdown")
136+
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
137+
require.NoError(t,err)
138+
}),
145139
}),
146140
uri:"repo://owner/repo/refs/heads/main/contents/README.md",
147141
handlerFn:func(depsToolDependencies) mcp.ResourceHandler {
@@ -158,12 +152,11 @@ func Test_repositoryResourceContents(t *testing.T) {
158152
{
159153
name:"successful text content fetch (tag)",
160154
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
161-
GetRawReposContentsByOwnerByRepoByTagByPath:
162-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
163-
w.Header().Set("Content-Type","text/markdown")
164-
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
165-
require.NoError(t,err)
166-
}),
155+
GetRawReposContentsByOwnerByRepoByTagByPath:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
156+
w.Header().Set("Content-Type","text/markdown")
157+
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
158+
require.NoError(t,err)
159+
}),
167160
}),
168161
uri:"repo://owner/repo/refs/tags/v1.0.0/contents/README.md",
169162
handlerFn:func(depsToolDependencies) mcp.ResourceHandler {
@@ -180,12 +173,11 @@ func Test_repositoryResourceContents(t *testing.T) {
180173
{
181174
name:"successful text content fetch (sha)",
182175
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
183-
GetRawReposContentsByOwnerByRepoBySHAByPath:
184-
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
185-
w.Header().Set("Content-Type","text/markdown")
186-
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
187-
require.NoError(t,err)
188-
}),
176+
GetRawReposContentsByOwnerByRepoBySHAByPath:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
177+
w.Header().Set("Content-Type","text/markdown")
178+
_,err:=w.Write([]byte("# Test Repository\n\nThis is a test repository."))
179+
require.NoError(t,err)
180+
}),
189181
}),
190182
uri:"repo://owner/repo/sha/abc123/contents/README.md",
191183
handlerFn:func(depsToolDependencies) mcp.ResourceHandler {
@@ -269,11 +261,11 @@ func Test_repositoryResourceContents(t *testing.T) {
269261

270262
content:=resp.Contents[0]
271263
switchtc.expectedResponseType {
272-
caseresourceResponseTypeBlob:
264+
caseresourceResponseTypeBlob:
273265
require.Equal(t,tc.expectedResult.Contents[0].Blob,content.Blob)
274-
caseresourceResponseTypeText:
266+
caseresourceResponseTypeText:
275267
require.Equal(t,tc.expectedResult.Contents[0].Text,content.Text)
276-
default:
268+
default:
277269
t.Fatalf("unknown expectedResponseType %v",tc.expectedResponseType)
278270
}
279271
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp