fix(delvh): loop milestones and choose more likely options first

Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
jolheiser 2023-07-15 20:54:28 -05:00
parent 87dd95d961
commit 5b87d1331c
No known key found for this signature in database
GPG Key ID: B853ADA5DA7BBF7A
1 changed files with 24 additions and 12 deletions

View File

@ -162,19 +162,31 @@ func (gh *GitHub) initClient(ctx context.Context) {
func (gh *GitHub) milestoneNum(ctx context.Context) (int, error) {
owner, repo := gh.OwnerRepo()
milestones, _, err := gh.client.Issues.ListMilestones(ctx, owner, repo, &github.MilestoneListOptions{
State: "all",
ListOptions: github.ListOptions{
PerPage: 100,
},
})
if err != nil {
return 0, err
}
p := 1
perPage := 100
for {
milestones, _, err := gh.client.Issues.ListMilestones(ctx, owner, repo, &github.MilestoneListOptions{
State: "all",
ListOptions: github.ListOptions{
Page: p,
PerPage: perPage,
},
Sort: "due_on",
Direction: "desc",
})
if err != nil {
return 0, err
}
p++
for _, milestone := range milestones {
if strings.EqualFold(milestone.GetTitle(), gh.Milestone) {
return milestone.GetNumber(), nil
for _, milestone := range milestones {
if strings.EqualFold(milestone.GetTitle(), gh.Milestone) {
return milestone.GetNumber(), nil
}
}
if len(milestones) != perPage {
break
}
}