package main import ( "bufio" "errors" "slices" "strings" "src.opensuse.org/autogits/common" "src.opensuse.org/autogits/common/gitea-generated/models" ) type PRInfo struct { pr *models.PullRequest reviews []*models.PullReview } type ReviewSet struct { prs []PRInfo config *common.AutogitConfig } 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 } } pr, err := gitea.GetPullRequest(org, repo, num) if err != nil { return nil, err } _, refPRs := common.ExtractDescriptionAndPRs(bufio.NewScanner(strings.NewReader(pr.Body))) /* if len(refPRs) < 1 { return nil, errors.New("missing links") } */ 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 } 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 } 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") }