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

Commitb820435

Browse files
authored
Fix: path param should be optional (#1631)
* Fix: path param should be optional* Add test
1 parentce2e4f9 commitb820435

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

‎pkg/github/repositories.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,13 @@ func GetFileContents(t translations.TranslationHelperFunc) inventory.ServerTool
670670
iferr!=nil {
671671
returnutils.NewToolResultError(err.Error()),nil,nil
672672
}
673-
path,err:=RequiredParam[string](args,"path")
673+
674+
path,err:=OptionalParam[string](args,"path")
674675
iferr!=nil {
675676
returnutils.NewToolResultError(err.Error()),nil,nil
676677
}
678+
path=strings.TrimPrefix(path,"/")
679+
677680
ref,err:=OptionalParam[string](args,"ref")
678681
iferr!=nil {
679682
returnutils.NewToolResultError(err.Error()),nil,nil

‎pkg/github/repositories_test.go‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,51 @@ func Test_GetFileContents(t *testing.T) {
245245
expectError:false,
246246
expectedResult:mockDirContent,
247247
},
248+
{
249+
name:"successful text content fetch with leading slash in path",
250+
mockedClient:mock.NewMockedHTTPClient(
251+
mock.WithRequestMatchHandler(
252+
mock.GetReposGitRefByOwnerByRepoByRef,
253+
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
254+
w.WriteHeader(http.StatusOK)
255+
_,_=w.Write([]byte(`{"ref": "refs/heads/main", "object": {"sha": ""}}`))
256+
}),
257+
),
258+
mock.WithRequestMatchHandler(
259+
mock.GetReposContentsByOwnerByRepoByPath,
260+
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
261+
w.WriteHeader(http.StatusOK)
262+
fileContent:=&github.RepositoryContent{
263+
Name:github.Ptr("README.md"),
264+
Path:github.Ptr("README.md"),
265+
SHA:github.Ptr("abc123"),
266+
Type:github.Ptr("file"),
267+
}
268+
contentBytes,_:=json.Marshal(fileContent)
269+
_,_=w.Write(contentBytes)
270+
}),
271+
),
272+
mock.WithRequestMatchHandler(
273+
raw.GetRawReposContentsByOwnerByRepoByBranchByPath,
274+
http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
275+
w.Header().Set("Content-Type","text/markdown")
276+
_,_=w.Write(mockRawContent)
277+
}),
278+
),
279+
),
280+
requestArgs:map[string]interface{}{
281+
"owner":"owner",
282+
"repo":"repo",
283+
"path":"/README.md",
284+
"ref":"refs/heads/main",
285+
},
286+
expectError:false,
287+
expectedResult: mcp.ResourceContents{
288+
URI:"repo://owner/repo/refs/heads/main/contents/README.md",
289+
Text:"# Test Repository\n\nThis is a test repository.",
290+
MIMEType:"text/markdown",
291+
},
292+
},
248293
{
249294
name:"content fetch fails",
250295
mockedClient:mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp