(ctx context.Context, client *githubv4.Client, owner string, repo string, issueNumber int)
| 947 | } |
| 948 | |
| 949 | func GetIssueLabels(ctx context.Context, client *githubv4.Client, owner string, repo string, issueNumber int) (*mcp.CallToolResult, error) { |
| 950 | // Get current labels on the issue using GraphQL |
| 951 | var query struct { |
| 952 | Repository struct { |
| 953 | Issue struct { |
| 954 | Labels struct { |
| 955 | Nodes []struct { |
| 956 | ID githubv4.ID |
| 957 | Name githubv4.String |
| 958 | Color githubv4.String |
| 959 | Description githubv4.String |
| 960 | } |
| 961 | TotalCount githubv4.Int |
| 962 | } `graphql:"labels(first: 100)"` |
| 963 | } `graphql:"issue(number: $issueNumber)"` |
| 964 | } `graphql:"repository(owner: $owner, name: $repo)"` |
| 965 | } |
| 966 | |
| 967 | vars := map[string]any{ |
| 968 | "owner": githubv4.String(owner), |
| 969 | "repo": githubv4.String(repo), |
| 970 | "issueNumber": githubv4.Int(issueNumber), // #nosec G115 - issue numbers are always small positive integers |
| 971 | } |
| 972 | |
| 973 | if err := client.Query(ctx, &query, vars); err != nil { |
| 974 | return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "Failed to get issue labels", err), nil |
| 975 | } |
| 976 | |
| 977 | // Extract label information |
| 978 | issueLabels := make([]map[string]any, len(query.Repository.Issue.Labels.Nodes)) |
| 979 | for i, label := range query.Repository.Issue.Labels.Nodes { |
| 980 | issueLabels[i] = map[string]any{ |
| 981 | "id": fmt.Sprintf("%v", label.ID), |
| 982 | "name": string(label.Name), |
| 983 | "color": string(label.Color), |
| 984 | "description": string(label.Description), |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | response := map[string]any{ |
| 989 | "labels": issueLabels, |
| 990 | "totalCount": int(query.Repository.Issue.Labels.TotalCount), |
| 991 | } |
| 992 | |
| 993 | out, err := json.Marshal(response) |
| 994 | if err != nil { |
| 995 | return nil, fmt.Errorf("failed to marshal response: %w", err) |
| 996 | } |
| 997 | |
| 998 | return utils.NewToolResultText(string(out)), nil |
| 999 | } |
| 1000 | |
| 1001 | // ListIssueTypes creates a tool to list defined issue types for an organization or repository. |
| 1002 | // This can be used to understand supported issue type values for creating or updating issues. |
no test coverage detected