package main import ( "encoding/json" "slices" "strings" "src.opensuse.org/autogits/common" ) type OrgLinks struct { Pkg string // fork to track SourceBranch string // branch to follow, empty for default TargetBranch string // branch in target repo, empty for default parentOrg, parentRepo string } func fetchProjectLinksFile(org, prj string) ([]byte, error) { return nil, nil } func parseProjectLinks(data []byte) ([]*OrgLinks, error) { values := make([]*OrgLinks, 0, 100) if len(data) == 0 { return values, nil } if err := json.Unmarshal(data, &values); err != nil { return nil, err } slices.SortFunc(values, func(a, b *OrgLinks) int { return strings.Compare(a.Pkg, b.Pkg) }) return values, nil } func ProcessProjectLinks(gitea common.Gitea, org, prjGit, branch string) ([]*OrgLinks, string, error) { data, hash, err := gitea.GetRepositoryFileContent(org, prjGit, branch, common.PrjLinksFile) if err != nil { return nil, "", err } links, err := parseProjectLinks(data) return links, hash, err } func ResolveLinks(org string, links []*OrgLinks, gitea common.GiteaRepoFetcher) { for _, link := range links { if repo, err := gitea.GetRepository(org, link.Pkg); err == nil { link.parentOrg = repo.Parent.Owner.UserName link.parentRepo = repo.Parent.Name if len(link.SourceBranch) == 0 { link.SourceBranch = repo.DefaultBranch } if len(link.TargetBranch) == 0 { link.TargetBranch = repo.Parent.DefaultBranch } } } } func ListenOrgsForUpdates(links []*OrgLinks) []string { orgs := make([]string, 0, len(links)) for _, link := range links { if !slices.Contains(orgs, link.parentOrg) { orgs = append(orgs, link.parentOrg) } } return orgs } func (link *OrgLinks) StateUpdater(git common.Git, gitea common.Gitea) { }