62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
"go.wit.com/lib/protobuf/httppb"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
func handleRepos(pb *gitpb.Repos, route string) error {
|
|
log.Info("GOT PATCHES ROUTE", route, "with # patches =", pb.Len())
|
|
if strings.HasPrefix(route, "/patches/old") {
|
|
} else if strings.HasPrefix(route, "/patches/new") {
|
|
log.Info("add new patches")
|
|
} else {
|
|
log.Info("unknown route", route)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// returns a repo PB with just the master and devel branch versions
|
|
// is just this information so it keeps things small when it's sent over the wire
|
|
func getCurrentRepoVersions(namespace string) *gitpb.Repo {
|
|
newrepo := new(gitpb.Repo)
|
|
newrepo.Namespace = namespace
|
|
found := me.forge.Repos.FindByNamespace(namespace)
|
|
if found == nil {
|
|
// todo: clone repo here
|
|
return newrepo
|
|
}
|
|
newrepo.MasterHash = found.MasterHash
|
|
newrepo.DevelHash = found.DevelHash
|
|
newrepo.URL = found.URL
|
|
return newrepo
|
|
}
|
|
|
|
func pullRequest(pb *gitpb.Repos, reqPB *httppb.HttpRequest) *gitpb.Repos {
|
|
versionsPB := gitpb.NewRepos()
|
|
for repo := range pb.IterAll() {
|
|
found := getCurrentRepoVersions(repo.Namespace)
|
|
versionsPB.Append(found)
|
|
}
|
|
return versionsPB
|
|
}
|
|
|
|
func addRequest(pb *gitpb.Repos, reqPB *httppb.HttpRequest) *gitpb.Repos {
|
|
newReposPB := gitpb.NewRepos()
|
|
for repo := range pb.IterAll() {
|
|
if found := me.forge.Repos.FindByNamespace(repo.Namespace); found != nil {
|
|
// already know about this namespace
|
|
continue
|
|
}
|
|
newrepo := new(gitpb.Repo)
|
|
newrepo.Namespace = repo.Namespace
|
|
newrepo.URL = repo.URL
|
|
newReposPB.Append(newrepo)
|
|
}
|
|
return newReposPB
|
|
}
|