@@ -536,7 +536,7 @@ func RepoMetadata(client *Client, repo ghrepo.Interface, input RepoMetadataInput
536536 if input .Milestones {
537537 count ++
538538 go func () {
539- milestones , err := RepoMilestones (client , repo )
539+ milestones , err := RepoMilestones (client , repo , "open" )
540540 if err != nil {
541541 err = fmt .Errorf ("error fetching milestones: %w" , err )
542542 }
@@ -797,8 +797,8 @@ type RepoMilestone struct {
797797 Title string
798798}
799799
800- // RepoMilestones fetches all open milestones in a repository
801- func RepoMilestones (client * Client , repo ghrepo.Interface ) ([]RepoMilestone , error ) {
800+ // RepoMilestones fetches milestones in a repository
801+ func RepoMilestones (client * Client , repo ghrepo.Interface , state string ) ([]RepoMilestone , error ) {
802802 type responseData struct {
803803 Repository struct {
804804 Milestones struct {
@@ -807,13 +807,26 @@ func RepoMilestones(client *Client, repo ghrepo.Interface) ([]RepoMilestone, err
807807 HasNextPage bool
808808 EndCursor string
809809 }
810- } `graphql:"milestones(states: [OPEN] , first: 100, after: $endCursor)"`
810+ } `graphql:"milestones(states: $states , first: 100, after: $endCursor)"`
811811 } `graphql:"repository(owner: $owner, name: $name)"`
812812 }
813813
814+ var states []githubv4.MilestoneState
815+ switch state {
816+ case "open" :
817+ states = []githubv4.MilestoneState {"OPEN" }
818+ case "closed" :
819+ states = []githubv4.MilestoneState {"CLOSED" }
820+ case "all" :
821+ states = []githubv4.MilestoneState {"OPEN" , "CLOSED" }
822+ default :
823+ return nil , fmt .Errorf ("invalid state: %s" , state )
824+ }
825+
814826 variables := map [string ]interface {}{
815827 "owner" : githubv4 .String (repo .RepoOwner ()),
816828 "name" : githubv4 .String (repo .RepoName ()),
829+ "states" : states ,
817830 "endCursor" : (* githubv4 .String )(nil ),
818831 }
819832
@@ -837,8 +850,8 @@ func RepoMilestones(client *Client, repo ghrepo.Interface) ([]RepoMilestone, err
837850 return milestones , nil
838851}
839852
840- func MilestoneByTitle (client * Client , repo ghrepo.Interface , title string ) (* RepoMilestone , error ) {
841- milestones , err := RepoMilestones (client , repo )
853+ func MilestoneByTitle (client * Client , repo ghrepo.Interface , state , title string ) (* RepoMilestone , error ) {
854+ milestones , err := RepoMilestones (client , repo , state )
842855 if err != nil {
843856 return nil , err
844857 }
0 commit comments