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

Commit02ebdc7

Browse files
committed
make required args explicit instead of panic
1 parentdb7a180 commit02ebdc7

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

‎pkg/github/repository_resource.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package github
33
import (
44
"context"
55
"encoding/base64"
6+
"errors"
67
"mime"
78
"path/filepath"
89
"strings"
@@ -60,30 +61,41 @@ func getRepositoryResourcePrContent(client *github.Client, t translations.Transl
6061

6162
funcrepositoryResourceContentsHandler(client*github.Client)func(ctx context.Context,request mcp.ReadResourceRequest) ([]mcp.ResourceContents,error) {
6263
returnfunc(ctx context.Context,request mcp.ReadResourceRequest) ([]mcp.ResourceContents,error) {
64+
// the matcher will give []string with one elemenent
65+
// https://github.com/mark3labs/mcp-go/pull/54
66+
o,ok:=request.Params.Arguments["owner"].([]string)
67+
if!ok||len(o)==0 {
68+
returnnil,errors.New("owner is required")
69+
}
70+
owner:=o[0]
71+
72+
r,ok:=request.Params.Arguments["repo"].([]string)
73+
if!ok||len(r)==0 {
74+
returnnil,errors.New("repo is required")
75+
}
76+
repo:=r[0]
6377

64-
owner:=request.Params.Arguments["owner"].([]string)[0]
65-
repo:=request.Params.Arguments["repo"].([]string)[0]
6678
// path should be a joined list of the path parts
6779
path:=strings.Join(request.Params.Arguments["path"].([]string),"/")
6880

6981
opts:=&github.RepositoryContentGetOptions{}
7082

7183
sha,ok:=request.Params.Arguments["sha"].([]string)
72-
ifok {
84+
ifok&&len(sha)>0{
7385
opts.Ref=sha[0]
7486
}
7587

7688
branch,ok:=request.Params.Arguments["branch"].([]string)
77-
ifok {
89+
ifok&&len(branch)>0{
7890
opts.Ref="refs/heads/"+branch[0]
7991
}
8092

8193
tag,ok:=request.Params.Arguments["tag"].([]string)
82-
ifok {
94+
ifok&&len(tag)>0{
8395
opts.Ref="refs/tags/"+tag[0]
8496
}
8597
prNumber,ok:=request.Params.Arguments["pr_number"].([]string)
86-
ifok {
98+
ifok&&len(prNumber)>0{
8799
opts.Ref="refs/pull/"+prNumber[0]+"/head"
88100
}
89101

‎pkg/github/repository_resource_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ func Test_repositoryResourceContentsHandler(t *testing.T) {
7070
expectedResultany
7171
expectedErrMsgstring
7272
}{
73+
{
74+
name:"missing owner",
75+
mockedClient:mock.NewMockedHTTPClient(
76+
mock.WithRequestMatch(
77+
mock.GetReposContentsByOwnerByRepoByPath,
78+
mockFileContent,
79+
),
80+
),
81+
requestArgs:map[string]any{},
82+
expectError:true,
83+
},
84+
{
85+
name:"missing repo",
86+
mockedClient:mock.NewMockedHTTPClient(
87+
mock.WithRequestMatch(
88+
mock.GetReposContentsByOwnerByRepoByPath,
89+
mockFileContent,
90+
),
91+
),
92+
requestArgs:map[string]any{
93+
"owner": []string{"owner"},
94+
},
95+
expectError:true,
96+
},
7397
{
7498
name:"successful file content fetch",
7599
mockedClient:mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp