58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
|
|
"src.opensuse.org/autogits/common"
|
|
)
|
|
|
|
type OrgLinks struct {
|
|
Source string // org/pkg
|
|
Target string // pkg
|
|
|
|
SOid, TOid string // source and target oids
|
|
}
|
|
|
|
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.Target, b.Target)
|
|
})
|
|
|
|
for _, link := range values {
|
|
if len(link.Source) < 3 {
|
|
return nil, fmt.Errorf("Invalid Source: %s", link.Source)
|
|
}
|
|
source_link := strings.Split(link.Source, "/")
|
|
if len(source_link) != 2 || len(source_link[0]) < 1 || len(source_link[1]) < 1 {
|
|
return nil, fmt.Errorf("Invalid Source: %s", link.Source)
|
|
}
|
|
if len(link.Target) < 1 {
|
|
return nil, fmt.Errorf("Missing Target for Source link: %s", link.Source)
|
|
}
|
|
}
|
|
|
|
return values, nil
|
|
}
|
|
|
|
func (link *OrgLinks) StateUpdater(git common.Git) {
|
|
|
|
}
|
|
|