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

Function uiGetMilestones

pkg/github/ui_tools.go:235–298  ·  view source on GitHub ↗
(ctx context.Context, deps ToolDependencies, args map[string]any, owner string)

Source from the content-addressed store, hash-verified

233}
234
235func uiGetMilestones(ctx context.Context, deps ToolDependencies, args map[string]any, owner string) (*mcp.CallToolResult, any, error) {
236 repo, err := RequiredParam[string](args, "repo")
237 if err != nil {
238 return utils.NewToolResultError(err.Error()), nil, nil
239 }
240
241 client, err := deps.GetClient(ctx)
242 if err != nil {
243 return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, nil
244 }
245
246 opts := &github.MilestoneListOptions{
247 State: "open",
248 ListOptions: github.ListOptions{PerPage: 100},
249 }
250
251 var allMilestones []*github.Milestone
252 hasMore := false
253 for page := 1; ; page++ {
254 milestones, resp, err := client.Issues.ListMilestones(ctx, owner, repo, opts)
255 if err != nil {
256 return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to list milestones", resp, err), nil, nil
257 }
258 allMilestones = append(allMilestones, milestones...)
259 if resp != nil && resp.Body != nil {
260 _ = resp.Body.Close()
261 }
262 if resp.NextPage == 0 {
263 break
264 }
265 if page >= uiGetMaxPages {
266 hasMore = true
267 break
268 }
269 opts.Page = resp.NextPage
270 }
271
272 result := make([]map[string]any, len(allMilestones))
273 for i, m := range allMilestones {
274 dueOn := ""
275 if m.DueOn != nil {
276 dueOn = m.GetDueOn().Format("2006-01-02")
277 }
278 result[i] = map[string]any{
279 "number": m.GetNumber(),
280 "title": m.GetTitle(),
281 "description": m.GetDescription(),
282 "state": m.GetState(),
283 "open_issues": m.GetOpenIssues(),
284 "due_on": dueOn,
285 }
286 }
287
288 out, err := json.Marshal(map[string]any{
289 "milestones": result,
290 "totalCount": len(result),
291 "has_more": hasMore,
292 })

Callers 1

UIGetFunction · 0.85

Calls 6

NewToolResultErrorFunction · 0.92
NewToolResultTextFunction · 0.92
CloseMethod · 0.80
GetClientMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected