MCPcopy
hub / github.com/github/github-mcp-server / OptionalStringArrayParam

Function OptionalStringArrayParam

pkg/github/params.go:245–269  ·  view source on GitHub ↗

OptionalStringArrayParam is a helper function that can be used to fetch a requested parameter from the request. It does the following checks: 1. Checks if the parameter is present in the request, if not, it returns its zero-value 2. If it is present, iterates the elements and checks each is a string

(args map[string]any, p string)

Source from the content-addressed store, hash-verified

243// 1. Checks if the parameter is present in the request, if not, it returns its zero-value
244// 2. If it is present, iterates the elements and checks each is a string
245func OptionalStringArrayParam(args map[string]any, p string) ([]string, error) {
246 // Check if the parameter is present in the request
247 if _, ok := args[p]; !ok {
248 return []string{}, nil
249 }
250
251 switch v := args[p].(type) {
252 case nil:
253 return []string{}, nil
254 case []string:
255 return v, nil
256 case []any:
257 strSlice := make([]string, len(v))
258 for i, v := range v {
259 s, ok := v.(string)
260 if !ok {
261 return []string{}, fmt.Errorf("parameter %s is not of type string, is %T", p, v)
262 }
263 strSlice[i] = s
264 }
265 return strSlice, nil
266 default:
267 return []string{}, fmt.Errorf("parameter %s could not be coerced to []string, is %T", p, args[p])
268 }
269}
270
271func convertStringSliceToBigIntSlice(s []string) ([]int64, error) {
272 int64Slice := make([]int64, len(s))

Callers 8

IssueWriteFunction · 0.85
ListIssuesFunction · 0.85
CreatePullRequestFunction · 0.85
UpdatePullRequestFunction · 0.85

Calls

no outgoing calls

Tested by 1