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

Commitdee5927

Browse files
authored
Fix binary files retrieval (#1183)
* tighten content filtering logic* add pdf retrieval test case* add application/xml check
1 parent94b3d72 commitdee5927

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

‎pkg/github/repositories.go‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,14 @@ func GetFileContents(getClient GetClientFn, getRawClient raw.GetRawClientFn, t t
601601
}
602602
}
603603

604-
ifstrings.HasPrefix(contentType,"application")||strings.HasPrefix(contentType,"text") {
604+
// Determine if content is text or binary
605+
isTextContent:=strings.HasPrefix(contentType,"text/")||
606+
contentType=="application/json"||
607+
contentType=="application/xml"||
608+
strings.HasSuffix(contentType,"+json")||
609+
strings.HasSuffix(contentType,"+xml")
610+
611+
ifisTextContent {
605612
result:= mcp.TextResourceContents{
606613
URI:resourceURI,
607614
Text:string(body),

‎pkg/github/repositories_test.go‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,51 @@ func Test_GetFileContents(t *testing.T) {
157157
MIMEType:"image/png",
158158
},
159159
},
160+
{
161+
name:"successful PDF file content fetch",
162+
mockedClient:mock.NewMockedHTTPClient(
163+
mock.WithRequestMatchHandler(
164+
mock.GetReposGitRefByOwnerByRepoByRef,
165+
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
166+
w.WriteHeader(http.StatusOK)
167+
_,_=w.Write([]byte(`{"ref": "refs/heads/main", "object": {"sha": ""}}`))
168+
}),
169+
),
170+
mock.WithRequestMatchHandler(
171+
mock.GetReposContentsByOwnerByRepoByPath,
172+
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
173+
w.WriteHeader(http.StatusOK)
174+
fileContent:=&github.RepositoryContent{
175+
Name:github.Ptr("document.pdf"),
176+
Path:github.Ptr("document.pdf"),
177+
SHA:github.Ptr("pdf123"),
178+
Type:github.Ptr("file"),
179+
}
180+
contentBytes,_:=json.Marshal(fileContent)
181+
_,_=w.Write(contentBytes)
182+
}),
183+
),
184+
mock.WithRequestMatchHandler(
185+
raw.GetRawReposContentsByOwnerByRepoByBranchByPath,
186+
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
187+
w.Header().Set("Content-Type","application/pdf")
188+
_,_=w.Write(mockRawContent)
189+
}),
190+
),
191+
),
192+
requestArgs:map[string]interface{}{
193+
"owner":"owner",
194+
"repo":"repo",
195+
"path":"document.pdf",
196+
"ref":"refs/heads/main",
197+
},
198+
expectError:false,
199+
expectedResult: mcp.BlobResourceContents{
200+
URI:"repo://owner/repo/refs/heads/main/contents/document.pdf",
201+
Blob:base64.StdEncoding.EncodeToString(mockRawContent),
202+
MIMEType:"application/pdf",
203+
},
204+
},
160205
{
161206
name:"successful directory content fetch",
162207
mockedClient:mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp