MCPcopy
hub / github.com/cli/cli / RepoMilestones

Function RepoMilestones

api/queries_repo.go:1456–1504  ·  view source on GitHub ↗

RepoMilestones fetches milestones in a repository

(client *Client, repo ghrepo.Interface, state string)

Source from the content-addressed store, hash-verified

1454
1455// RepoMilestones fetches milestones in a repository
1456func RepoMilestones(client *Client, repo ghrepo.Interface, state string) ([]RepoMilestone, error) {
1457 type responseData struct {
1458 Repository struct {
1459 Milestones struct {
1460 Nodes []RepoMilestone
1461 PageInfo struct {
1462 HasNextPage bool
1463 EndCursor string
1464 }
1465 } `graphql:"milestones(states: $states, first: 100, after: $endCursor)"`
1466 } `graphql:"repository(owner: $owner, name: $name)"`
1467 }
1468
1469 var states []githubv4.MilestoneState
1470 switch state {
1471 case "open":
1472 states = []githubv4.MilestoneState{"OPEN"}
1473 case "closed":
1474 states = []githubv4.MilestoneState{"CLOSED"}
1475 case "all":
1476 states = []githubv4.MilestoneState{"OPEN", "CLOSED"}
1477 default:
1478 return nil, fmt.Errorf("invalid state: %s", state)
1479 }
1480
1481 variables := map[string]interface{}{
1482 "owner": githubv4.String(repo.RepoOwner()),
1483 "name": githubv4.String(repo.RepoName()),
1484 "states": states,
1485 "endCursor": (*githubv4.String)(nil),
1486 }
1487
1488 var milestones []RepoMilestone
1489 for {
1490 var query responseData
1491 err := client.Query(repo.RepoHost(), "RepositoryMilestoneList", &query, variables)
1492 if err != nil {
1493 return nil, err
1494 }
1495
1496 milestones = append(milestones, query.Repository.Milestones.Nodes...)
1497 if !query.Repository.Milestones.PageInfo.HasNextPage {
1498 break
1499 }
1500 variables["endCursor"] = githubv4.String(query.Repository.Milestones.PageInfo.EndCursor)
1501 }
1502
1503 return milestones, nil
1504}
1505
1506// v1Projects retrieves set of RepoProjects relevant to given repository:
1507// - Projects for repository

Callers 2

Test_RepoMilestonesFunction · 0.85
RepoMetadataFunction · 0.85

Calls 6

ErrorfMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
QueryMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.45

Tested by 1

Test_RepoMilestonesFunction · 0.68