github: use ListByRepo instead of global Issue Search

This commit is contained in:
6543 2023-06-23 15:00:48 +02:00
parent 07c0fc1414
commit df18780b5a
No known key found for this signature in database
GPG Key ID: B8BE6D610E61C862
1 changed files with 12 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import (
"fmt"
"net/http"
"os"
"strings"
"time"
"github.com/google/go-github/v50/github"
@ -38,15 +39,22 @@ func (gh *GitHub) Generate() (string, []Entry, error) {
state = "closed"
}
query := fmt.Sprintf(`repo:%s is:%s milestone:"%s"`, gh.Repo, state, gh.Milestone)
repoParts := strings.SplitN(gh.Repo, "/", 2)
if len(repoParts) != 2 {
return "", nil, fmt.Errorf("repo: '%s' can not be split into repoOwner and repoName", gh.Repo)
}
p := 1
perPage := 100
for {
result, _, err := client.Search.Issues(ctx, query, &github.SearchOptions{
result, _, err := client.Issues.ListByRepo(ctx, "owner", "repo", &github.IssueListByRepoOptions{
ListOptions: github.ListOptions{
Page: p,
PerPage: perPage,
},
State: state,
Milestone: gh.Milestone,
})
if err != nil {
return "", nil, err
@ -55,7 +63,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) {
isPull := !(gh.Issues)
for _, pr := range result.Issues {
for _, pr := range result {
if pr.IsPullRequest() == isPull {
p := Entry{
Title: CleanTitle(pr.GetTitle()),
@ -74,7 +82,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) {
}
}
if len(result.Issues) != perPage {
if len(result) != perPage {
break
}
}