MCPcopy Index your code
hub / github.com/github/github-mcp-server / OptionalParam

Function OptionalParam

pkg/github/params.go:180–194  ·  view source on GitHub ↗

OptionalParam 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, it checks if the parameter is of the expected type and retur

(args map[string]any, p string)

Source from the content-addressed store, hash-verified

178// 1. Checks if the parameter is present in the request, if not, it returns its zero-value
179// 2. If it is present, it checks if the parameter is of the expected type and returns it
180func OptionalParam[T any](args map[string]any, p string) (T, error) {
181 var zero T
182
183 // Check if the parameter is present in the request
184 if _, ok := args[p]; !ok {
185 return zero, nil
186 }
187
188 // Check if the parameter is of the expected type
189 if _, ok := args[p].(T); !ok {
190 return zero, fmt.Errorf("parameter %s is not of type %T, is %T", p, zero, args[p])
191 }
192
193 return args[p].(T), nil
194}
195
196// OptionalIntParam is a helper function that can be used to fetch a requested parameter from the request.
197// It does the following checks:

Callers 3

ActionsRunTriggerFunction · 0.85
listWorkflowRunsFunction · 0.85
listWorkflowJobsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected