(ctx context.Context, accountType string, deps ToolDependencies, args map[string]any)
| 319 | } |
| 320 | |
| 321 | func userOrOrgHandler(ctx context.Context, accountType string, deps ToolDependencies, args map[string]any) (*mcp.CallToolResult, any, error) { |
| 322 | query, err := RequiredParam[string](args, "query") |
| 323 | if err != nil { |
| 324 | return utils.NewToolResultError(err.Error()), nil, nil |
| 325 | } |
| 326 | sort, err := OptionalParam[string](args, "sort") |
| 327 | if err != nil { |
| 328 | return utils.NewToolResultError(err.Error()), nil, nil |
| 329 | } |
| 330 | order, err := OptionalParam[string](args, "order") |
| 331 | if err != nil { |
| 332 | return utils.NewToolResultError(err.Error()), nil, nil |
| 333 | } |
| 334 | pagination, err := OptionalPaginationParams(args) |
| 335 | if err != nil { |
| 336 | return utils.NewToolResultError(err.Error()), nil, nil |
| 337 | } |
| 338 | |
| 339 | opts := &github.SearchOptions{ |
| 340 | Sort: sort, |
| 341 | Order: order, |
| 342 | ListOptions: github.ListOptions{ |
| 343 | PerPage: pagination.PerPage, |
| 344 | Page: pagination.Page, |
| 345 | }, |
| 346 | } |
| 347 | |
| 348 | client, err := deps.GetClient(ctx) |
| 349 | if err != nil { |
| 350 | return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil |
| 351 | } |
| 352 | |
| 353 | searchQuery := query |
| 354 | if !hasTypeFilter(query) { |
| 355 | searchQuery = "type:" + accountType + " " + query |
| 356 | } |
| 357 | result, resp, err := client.Search.Users(ctx, searchQuery, opts) |
| 358 | if err != nil { |
| 359 | return ghErrors.NewGitHubAPIErrorResponse(ctx, |
| 360 | fmt.Sprintf("failed to search %ss with query '%s'", accountType, query), |
| 361 | resp, |
| 362 | err, |
| 363 | ), nil, nil |
| 364 | } |
| 365 | defer func() { _ = resp.Body.Close() }() |
| 366 | |
| 367 | if resp.StatusCode != http.StatusOK { |
| 368 | body, err := io.ReadAll(resp.Body) |
| 369 | if err != nil { |
| 370 | return utils.NewToolResultErrorFromErr("failed to read response body", err), nil, nil |
| 371 | } |
| 372 | return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, fmt.Sprintf("failed to search %ss", accountType), resp, body), nil, nil |
| 373 | } |
| 374 | |
| 375 | minimalUsers := make([]MinimalUser, 0, len(result.Users)) |
| 376 | |
| 377 | for _, user := range result.Users { |
| 378 | if user.Login != nil { |
no test coverage detected