Helper functions for consolidated projects tools
(ctx context.Context, client *github.Client, args map[string]any, owner, ownerType string)
| 702 | // Helper functions for consolidated projects tools |
| 703 | |
| 704 | func listProjects(ctx context.Context, client *github.Client, args map[string]any, owner, ownerType string) (*mcp.CallToolResult, []bool, any, error) { |
| 705 | queryStr, err := OptionalParam[string](args, "query") |
| 706 | if err != nil { |
| 707 | return utils.NewToolResultError(err.Error()), nil, nil, nil |
| 708 | } |
| 709 | |
| 710 | pagination, err := extractPaginationOptionsFromArgs(args) |
| 711 | if err != nil { |
| 712 | return utils.NewToolResultError(err.Error()), nil, nil, nil |
| 713 | } |
| 714 | |
| 715 | var resp *github.Response |
| 716 | var projects []*github.ProjectV2 |
| 717 | |
| 718 | minimalProjects := []MinimalProject{} |
| 719 | opts := &github.ListProjectsOptions{ |
| 720 | ListProjectsPaginationOptions: pagination, |
| 721 | Query: queryStr, |
| 722 | } |
| 723 | |
| 724 | // If owner_type not provided, fetch from both user and org |
| 725 | switch ownerType { |
| 726 | case "": |
| 727 | return listProjectsFromBothOwnerTypes(ctx, client, owner, opts) |
| 728 | case "org": |
| 729 | projects, resp, err = client.Projects.ListOrganizationProjects(ctx, owner, opts) |
| 730 | if err != nil { |
| 731 | return ghErrors.NewGitHubAPIErrorResponse(ctx, |
| 732 | "failed to list projects", |
| 733 | resp, |
| 734 | err, |
| 735 | ), nil, nil, nil |
| 736 | } |
| 737 | default: |
| 738 | projects, resp, err = client.Projects.ListUserProjects(ctx, owner, opts) |
| 739 | if err != nil { |
| 740 | return ghErrors.NewGitHubAPIErrorResponse(ctx, |
| 741 | "failed to list projects", |
| 742 | resp, |
| 743 | err, |
| 744 | ), nil, nil, nil |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | // For specified owner_type, process normally |
| 749 | if ownerType != "" { |
| 750 | defer func() { _ = resp.Body.Close() }() |
| 751 | |
| 752 | for _, project := range projects { |
| 753 | mp := convertToMinimalProject(project) |
| 754 | mp.OwnerType = ownerType |
| 755 | minimalProjects = append(minimalProjects, *mp) |
| 756 | } |
| 757 | |
| 758 | response := map[string]any{ |
| 759 | "projects": minimalProjects, |
| 760 | "pageInfo": buildPageInfo(resp), |
| 761 | } |
no test coverage detected