package main import ( "encoding/json" "errors" "src.opensuse.org/autogits/common" ) //go:generate mockgen -source=maintainership.go -destination=mock/maintainership.go -typed const ProjectKey = "*" type MaintainershipMap map[string]interface{} type GiteaMaintainershipInterface interface { FetchMaintainershipFile(org, prj, branch string) ([]byte, error) } func MaintainerListForProject(gitea GiteaMaintainershipInterface, org, branch string) ([]string, error) { data, err := gitea.FetchMaintainershipFile(org, common.DefaultGitPrj, branch) if err != nil || data == nil { return nil, err } maintainer := make(MaintainershipMap) if err := json.Unmarshal(data, &maintainer); err != nil { return nil, err } m, found := maintainer[ProjectKey] if !found { return nil, nil } invalidTypeErr := errors.New("Invalid type") switch m.(type) { case []interface{}: maintainers := make([]string, 0) for _, v := range m.([]interface{}) { if _, ok := v.(string); !ok { return nil, invalidTypeErr } maintainers = append(maintainers, v.(string)) } return maintainers, nil case string: return []string{m.(string)}, nil default: return nil, invalidTypeErr } } func MaintainerListForPackage(gitea GiteaMaintainershipInterface, org, pkg, branch string) ([]string, error) { _, err := gitea.FetchMaintainershipFile(org, pkg, branch) if err != nil { return nil, err } return []string{}, nil }