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,37 +401,41 @@ func (gitea *GiteaTransport) AddReviewComment(pr *models.PullRequest, state mode
} }
func (gitea *GiteaTransport) GetAssociatedPrjGitPR(pr *PullRequestWebhookEvent) (*models.PullRequest, error) { func (gitea *GiteaTransport) GetAssociatedPrjGitPR(pr *PullRequestWebhookEvent) (*models.PullRequest, error) {
var page, maxSize int64 var page int64
page = 1
maxSize = 10000
state := "open" state := "open"
prs, err := gitea.client.Repository.RepoListPullRequests( for {
repository. page++
NewRepoListPullRequestsParams(). prs, err := gitea.client.Repository.RepoListPullRequests(
WithDefaults(). repository.
WithOwner(pr.Repository.Owner.Username). NewRepoListPullRequestsParams().
WithRepo(DefaultGitPrj). WithDefaults().
WithState(&state). WithOwner(pr.Repository.Owner.Username).
WithLimit(&maxSize). WithRepo(DefaultGitPrj).
WithPage(&page), WithState(&state).
gitea.transport.DefaultAuthentication) WithPage(&page),
gitea.transport.DefaultAuthentication)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot fetch PR list for %s / %s : %w", pr.Repository.Owner.Username, pr.Repository.Name, err) return nil, fmt.Errorf("cannot fetch PR list for %s / %s : %w", pr.Repository.Owner.Username, pr.Repository.Name, err)
} }
prLine := fmt.Sprintf(PrPattern, pr.Repository.Owner.Username, pr.Repository.Name, pr.Number) prLine := fmt.Sprintf(PrPattern, pr.Repository.Owner.Username, pr.Repository.Name, pr.Number)
// h.StdLogger.Printf("attemping to match line: '%s'\n", prLine) // h.StdLogger.Printf("attemping to match line: '%s'\n", prLine)
// payload_processing: // payload_processing:
for _, pr := range prs.Payload { for _, pr := range prs.Payload {
lines := strings.Split(pr.Body, "\n") lines := strings.Split(pr.Body, "\n")
for _, line := range lines { for _, line := range lines {
if strings.TrimSpace(line) == prLine { if strings.TrimSpace(line) == prLine {
return pr, nil return pr, nil
}
} }
} }
if len(prs.Payload) < 10 {
break
}
} }
return nil, nil 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 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 break
} }