Skip to content
Prev Previous commit
Next Next commit
refactor: update optionalParamsOK as exported member
  • Loading branch information
monotykamary committed Apr 8, 2025
commit 57d2a4281b60901b08b1f32e516cf3ee66037712
6 changes: 3 additions & 3 deletions pkg/github/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestOptionalParamOK(t *testing.T) {

// Test with string type assertion
if _, isString := tc.expectedVal.(string); isString || tc.errorMsg == "parameter myParam is not of type string, is bool" {
val, ok, err := optionalParamOK[string](request, tc.paramName)
val, ok, err := OptionalParamOK[string](request, tc.paramName)
if tc.expectError {
require.Error(t, err)
assert.Contains(t, err.Error(), tc.errorMsg)
Expand All @@ -177,7 +177,7 @@ func TestOptionalParamOK(t *testing.T) {

// Test with bool type assertion
if _, isBool := tc.expectedVal.(bool); isBool || tc.errorMsg == "parameter myParam is not of type bool, is string" {
val, ok, err := optionalParamOK[bool](request, tc.paramName)
val, ok, err := OptionalParamOK[bool](request, tc.paramName)
if tc.expectError {
require.Error(t, err)
assert.Contains(t, err.Error(), tc.errorMsg)
Expand All @@ -192,7 +192,7 @@ func TestOptionalParamOK(t *testing.T) {

// Test with float64 type assertion (for number case)
if _, isFloat := tc.expectedVal.(float64); isFloat {
val, ok, err := optionalParamOK[float64](request, tc.paramName)
val, ok, err := OptionalParamOK[float64](request, tc.paramName)
if tc.expectError {
// This case shouldn't happen for float64 in the defined tests
require.Fail(t, "Unexpected error case for float64")
Expand Down
10 changes: 5 additions & 5 deletions pkg/github/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,35 +118,35 @@ func UpdatePullRequest(client *github.Client, t translations.TranslationHelperFu
update := &github.PullRequest{}
updateNeeded := false

if title, ok, err := optionalParamOK[string](request, "title"); err != nil {
if title, ok, err := OptionalParamOK[string](request, "title"); err != nil {
return mcp.NewToolResultError(err.Error()), nil
} else if ok {
update.Title = github.Ptr(title)
updateNeeded = true
}

if body, ok, err := optionalParamOK[string](request, "body"); err != nil {
if body, ok, err := OptionalParamOK[string](request, "body"); err != nil {
return mcp.NewToolResultError(err.Error()), nil
} else if ok {
update.Body = github.Ptr(body)
updateNeeded = true
}

if state, ok, err := optionalParamOK[string](request, "state"); err != nil {
if state, ok, err := OptionalParamOK[string](request, "state"); err != nil {
return mcp.NewToolResultError(err.Error()), nil
} else if ok {
update.State = github.Ptr(state)
updateNeeded = true
}

if base, ok, err := optionalParamOK[string](request, "base"); err != nil {
if base, ok, err := OptionalParamOK[string](request, "base"); err != nil {
return mcp.NewToolResultError(err.Error()), nil
} else if ok {
update.Base = &github.PullRequestBranch{Ref: github.Ptr(base)}
updateNeeded = true
}

if maintainerCanModify, ok, err := optionalParamOK[bool](request, "maintainer_can_modify"); err != nil {
if maintainerCanModify, ok, err := OptionalParamOK[bool](request, "maintainer_can_modify"); err != nil {
return mcp.NewToolResultError(err.Error()), nil
} else if ok {
update.MaintainerCanModify = github.Ptr(maintainerCanModify)
Expand Down
4 changes: 2 additions & 2 deletions pkg/github/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func GetMe(client *github.Client, t translations.TranslationHelperFunc) (tool mc
}
}

// optionalParamOK is a helper function that can be used to fetch a requested parameter from the request.
// OptionalParamOK is a helper function that can be used to fetch a requested parameter from the request.
// It returns the value, a boolean indicating if the parameter was present, and an error if the type is wrong.
func optionalParamOK[T any](r mcp.CallToolRequest, p string) (value T, ok bool, err error) {
func OptionalParamOK[T any](r mcp.CallToolRequest, p string) (value T, ok bool, err error) {
// Check if the parameter is present in the request
val, exists := r.Params.Arguments[p]
if !exists {
Expand Down