common: refactor IsReviewed()

This commit is contained in:
Adam Majer 2024-10-01 12:18:37 +02:00
parent 77bdf7649a
commit 881cba862f

View File

@ -297,17 +297,15 @@ func (gitea *GiteaTransport) RequestReviews(pr *models.PullRequest, reviewer str
func (gitea *GiteaTransport) IsReviewed(pr *models.PullRequest) (bool, error) { func (gitea *GiteaTransport) IsReviewed(pr *models.PullRequest) (bool, error) {
// TODO: get review from project git // TODO: get review from project git
reviewers := pr.RequestedReviewers reviewers := pr.RequestedReviewers
var page, limit int64 var page int64
var reviews []*models.PullReview reviews := make([]*models.PullReview, 0, 10)
page = 0
limit = 20
for { for {
page++
res, err := gitea.client.Repository.RepoListPullReviews( res, err := gitea.client.Repository.RepoListPullReviews(
repository.NewRepoListPullReviewsParams(). repository.NewRepoListPullReviewsParams().
WithOwner(pr.Base.Repo.Owner.UserName). WithOwner(pr.Base.Repo.Owner.UserName).
WithRepo(pr.Base.Repo.Name). WithRepo(pr.Base.Repo.Name).
WithPage(&page). WithPage(&page),
WithLimit(&limit),
gitea.transport.DefaultAuthentication) gitea.transport.DefaultAuthentication)
if err != nil { if err != nil {
@ -315,15 +313,8 @@ func (gitea *GiteaTransport) IsReviewed(pr *models.PullRequest) (bool, error) {
} }
if res.IsSuccess() { if res.IsSuccess() {
r := res.Payload reviews = append(reviews, res.Payload...)
if len(res.Payload) < 10 {
if reviews == nil {
reviews = r
} else {
reviews = append(reviews, r...)
}
if len(r) < int(limit) {
break break
} }
} }