2024-12-02 10:26:51 +01:00
|
|
|
package main
|
|
|
|
|
2024-12-04 08:55:40 +01:00
|
|
|
import (
|
2024-12-17 23:33:43 +01:00
|
|
|
"bufio"
|
|
|
|
"errors"
|
|
|
|
"slices"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"src.opensuse.org/autogits/common"
|
2024-12-04 08:55:40 +01:00
|
|
|
"src.opensuse.org/autogits/common/gitea-generated/models"
|
|
|
|
)
|
|
|
|
|
2024-12-17 23:33:43 +01:00
|
|
|
type PRInfo struct {
|
|
|
|
pr *models.PullRequest
|
|
|
|
reviews []*models.PullReview
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReviewSet struct {
|
2024-12-18 17:30:00 +01:00
|
|
|
prs []PRInfo
|
|
|
|
config *common.AutogitConfig
|
2024-12-17 23:33:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func readPRData(gitea common.GiteaPRFetcher, org, repo string, num int64, currentSet []PRInfo) ([]PRInfo, error) {
|
|
|
|
for _, p := range currentSet {
|
|
|
|
if num == p.pr.Index && repo == p.pr.Base.Repo.Name && org == p.pr.Base.Repo.Owner.UserName {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
2024-12-05 18:38:35 +01:00
|
|
|
|
2024-12-17 23:33:43 +01:00
|
|
|
pr, err := gitea.GetPullRequest(org, repo, num)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
_, refPRs := common.ExtractDescriptionAndPRs(bufio.NewScanner(strings.NewReader(pr.Body)))
|
2024-12-18 17:30:00 +01:00
|
|
|
/*
|
2024-12-17 23:33:43 +01:00
|
|
|
if len(refPRs) < 1 {
|
|
|
|
return nil, errors.New("missing links")
|
|
|
|
}
|
2024-12-18 17:30:00 +01:00
|
|
|
*/
|
2024-12-17 23:33:43 +01:00
|
|
|
|
|
|
|
retSet := []PRInfo{PRInfo{pr: pr}}
|
|
|
|
|
|
|
|
for _, prdata := range refPRs {
|
|
|
|
data, err := readPRData(gitea, prdata.Org, prdata.Repo, prdata.Num, slices.Concat(currentSet, retSet))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
retSet = slices.Concat(retSet, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
return retSet, nil
|
2024-12-04 08:55:40 +01:00
|
|
|
}
|
|
|
|
|
2024-12-17 23:33:43 +01:00
|
|
|
func FetchReviewSet(gitea common.GiteaPRFetcher, org, repo string, num int64, config *common.AutogitConfig) (*ReviewSet, error) {
|
|
|
|
prs, err := readPRData(gitea, org, repo, num, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-12-18 17:30:00 +01:00
|
|
|
return &ReviewSet{prs: prs, config: config}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rs *ReviewSet) GetPrjGitPR() (*models.PullRequest, error) {
|
|
|
|
for _, prinfo := range rs.prs {
|
|
|
|
if prinfo.pr.Base.Repo.Name == rs.config.GitProjectName && prinfo.pr.Base.Repo.Owner.UserName == rs.config.Organization {
|
|
|
|
return prinfo.pr, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errors.New("No PrjGit PR found")
|
2024-12-17 23:33:43 +01:00
|
|
|
}
|
2024-12-09 00:39:55 +01:00
|
|
|
|