From df18780b5a2a2cd2fe07737634e8882caf0e41f3 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 23 Jun 2023 15:00:48 +0200 Subject: [PATCH] github: use ListByRepo instead of global Issue Search --- service/github.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/service/github.go b/service/github.go index 00894b6..a066241 100644 --- a/service/github.go +++ b/service/github.go @@ -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 } }