MCPcopy Create free account
hub / github.com/cli/cli / RepoMilestones

Function RepoMilestones

api/queries_repo.go:1461–1509  ·  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

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

Callers 2

Test_RepoMilestonesFunction · 0.85
RepoMetadataFunction · 0.85

Calls 6

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

Tested by 1

Test_RepoMilestonesFunction · 0.68