77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"src.opensuse.org/autogits/common"
|
|
"src.opensuse.org/autogits/common/gitea-generated/models"
|
|
)
|
|
|
|
//go:generate mockgen -source=maintainership.go -destination=mock/maintainership.go -typed
|
|
|
|
const ProjectKey = ""
|
|
|
|
type MaintainershipMap map[string][]string
|
|
|
|
type GiteaMaintainershipInterface interface {
|
|
FetchMaintainershipFile(org, prjGit, branch string) ([]byte, error)
|
|
GetPullRequestAndReviews(org, pkg string, num int64) (*models.PullRequest, []*models.PullReview, error)
|
|
}
|
|
|
|
func parseMaintainershipData(data []byte) (MaintainershipMap, error) {
|
|
maintainers := make(MaintainershipMap)
|
|
if err := json.Unmarshal(data, &maintainers); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return maintainers, nil
|
|
}
|
|
|
|
func ProjectMaintainershipData(gitea GiteaMaintainershipInterface, org, prjGit, branch string) (MaintainershipMap, error) {
|
|
data, err := gitea.FetchMaintainershipFile(org, prjGit, branch)
|
|
if err != nil || data == nil {
|
|
return nil, err
|
|
}
|
|
|
|
return parseMaintainershipData(data)
|
|
}
|
|
|
|
func MaintainerListForProject(maintainers MaintainershipMap) []string {
|
|
m, found := maintainers[ProjectKey]
|
|
if !found {
|
|
return nil
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func MaintainerListForPackage(maintainers MaintainershipMap, pkg string) []string {
|
|
pkgMaintainers := maintainers[pkg]
|
|
prjMaintainers := maintainers[ProjectKey]
|
|
|
|
prjMaintainer:
|
|
for _, prjm := range prjMaintainers {
|
|
for i := range pkgMaintainers {
|
|
if pkgMaintainers[i] == prjm {
|
|
continue prjMaintainer
|
|
}
|
|
}
|
|
pkgMaintainers = append(pkgMaintainers, prjm)
|
|
}
|
|
|
|
return pkgMaintainers
|
|
}
|
|
|
|
func CheckIfMaintainersApproved(gitea GiteaMaintainershipInterface, config common.AutogitConfig, prjGitPRNumber int64) (bool, error) {
|
|
gitea.GetPullRequestAndReviews(config.Organization, config.GitProjectName, prjGitPRNumber)
|
|
gitea.FetchMaintainershipFile(config.Organization, config.GitProjectName, config.Branch)
|
|
|
|
/*
|
|
pr, reviews, _ := gitea.GetPullRequestAndReviews(config.Organization, config.GitProjectName, prjGitPRNumber)
|
|
data, _ := gitea.FetchMaintainershipFile(config.Organization, config.GitProjectName, config.Branch)
|
|
|
|
maintainers, _ := parseMaintainershipData(data)
|
|
*/
|
|
return false, nil
|
|
}
|