@@ -536,7 +536,7 @@ func RepoMetadata(client *Client, repo ghrepo.Interface, input RepoMetadataInput
536
536
if input .Milestones {
537
537
count ++
538
538
go func () {
539
- milestones , err := RepoMilestones (client , repo )
539
+ milestones , err := RepoMilestones (client , repo , "open" )
540
540
if err != nil {
541
541
err = fmt .Errorf ("error fetching milestones: %w" , err )
542
542
}
@@ -797,8 +797,8 @@ type RepoMilestone struct {
797
797
Title string
798
798
}
799
799
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 ) {
802
802
type responseData struct {
803
803
Repository struct {
804
804
Milestones struct {
@@ -807,13 +807,26 @@ func RepoMilestones(client *Client, repo ghrepo.Interface) ([]RepoMilestone, err
807
807
HasNextPage bool
808
808
EndCursor string
809
809
}
810
- } `graphql:"milestones(states: [OPEN] , first: 100, after: $endCursor)"`
810
+ } `graphql:"milestones(states: $states , first: 100, after: $endCursor)"`
811
811
} `graphql:"repository(owner: $owner, name: $name)"`
812
812
}
813
813
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
+
814
826
variables := map [string ]interface {}{
815
827
"owner" : githubv4 .String (repo .RepoOwner ()),
816
828
"name" : githubv4 .String (repo .RepoName ()),
829
+ "states" : states ,
817
830
"endCursor" : (* githubv4 .String )(nil ),
818
831
}
819
832
@@ -837,8 +850,8 @@ func RepoMilestones(client *Client, repo ghrepo.Interface) ([]RepoMilestone, err
837
850
return milestones , nil
838
851
}
839
852
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 )
842
855
if err != nil {
843
856
return nil , err
844
857
}
0 commit comments