common: parse all PR for associated PrjGit PR
we may have more than 1 page of PR to parse
This commit is contained in:
parent
a0a79dcf4d
commit
77bdf7649a
@ -401,37 +401,41 @@ 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"
|
||||
prs, err := gitea.client.Repository.RepoListPullRequests(
|
||||
repository.
|
||||
NewRepoListPullRequestsParams().
|
||||
WithDefaults().
|
||||
WithOwner(pr.Repository.Owner.Username).
|
||||
WithRepo(DefaultGitPrj).
|
||||
WithState(&state).
|
||||
WithLimit(&maxSize).
|
||||
WithPage(&page),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
for {
|
||||
page++
|
||||
prs, err := gitea.client.Repository.RepoListPullRequests(
|
||||
repository.
|
||||
NewRepoListPullRequestsParams().
|
||||
WithDefaults().
|
||||
WithOwner(pr.Repository.Owner.Username).
|
||||
WithRepo(DefaultGitPrj).
|
||||
WithState(&state).
|
||||
WithPage(&page),
|
||||
gitea.transport.DefaultAuthentication)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot fetch PR list for %s / %s : %w", pr.Repository.Owner.Username, pr.Repository.Name, err)
|
||||
}
|
||||
if err != nil {
|
||||
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)
|
||||
// h.StdLogger.Printf("attemping to match line: '%s'\n", prLine)
|
||||
prLine := fmt.Sprintf(PrPattern, pr.Repository.Owner.Username, pr.Repository.Name, pr.Number)
|
||||
// h.StdLogger.Printf("attemping to match line: '%s'\n", prLine)
|
||||
|
||||
// payload_processing:
|
||||
for _, pr := range prs.Payload {
|
||||
lines := strings.Split(pr.Body, "\n")
|
||||
// payload_processing:
|
||||
for _, pr := range prs.Payload {
|
||||
lines := strings.Split(pr.Body, "\n")
|
||||
|
||||
for _, line := range lines {
|
||||
if strings.TrimSpace(line) == prLine {
|
||||
return pr, nil
|
||||
for _, line := range lines {
|
||||
if strings.TrimSpace(line) == prLine {
|
||||
return pr, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user