common: parse all PR for associated PrjGit PR

we may have more than 1 page of PR to parse
This commit is contained in:
Adam Majer 2024-10-01 12:03:50 +02:00
parent a0a79dcf4d
commit 77bdf7649a

View File

@ -401,10 +401,10 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
}
func (gitea *GiteaTransport) GetAssociatedPrjGitPR(pr *PullRequestWebhookEvent) (*models.PullRequest, error) {
var page, maxSize int64
page = 1
maxSize = 10000
var page int64
state := "open"
for {
page++
prs, err := gitea.client.Repository.RepoListPullRequests(
repository.
NewRepoListPullRequestsParams().
@ -412,7 +412,6 @@ func (gitea *GiteaTransport) GetAssociatedPrjGitPR(pr *PullRequestWebhookEvent)
WithOwner(pr.Repository.Owner.Username).
WithRepo(DefaultGitPrj).
WithState(&state).
WithLimit(&maxSize).
WithPage(&page),
gitea.transport.DefaultAuthentication)
@ -434,6 +433,11 @@ func (gitea *GiteaTransport) GetAssociatedPrjGitPR(pr *PullRequestWebhookEvent)
}
}
if len(prs.Payload) < 10 {
break
}
}
return nil, nil
}
@ -494,7 +498,7 @@ func (gitea *GiteaTransport) GetRecentPullRequests(org, repo string) ([]*models.
}
// if pr is closed for more than a week, assume that we are done too
if time.Since(time.Time(res.Payload[n-1].Updated)) > 7 * 24 * time.Hour {
if time.Since(time.Time(res.Payload[n-1].Updated)) > 7*24*time.Hour {
break
}