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