add /update

This commit is contained in:
Jeff Carr 2025-07-08 17:13:58 -05:00
parent e57f48e649
commit 3588440aed
3 changed files with 69 additions and 1 deletions

View File

@ -1,7 +1,7 @@
.PHONY: build
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
all: build
@echo "make build # build"

View File

@ -205,6 +205,7 @@ func lookupRepos(msg []byte) (*gitpb.Repos, error) {
}
return newpb, nil
}
/* save the git.pb files
+ if repo.Namespace == "" {
+ log.Infof("repo: ERROR. no namespace. %s\n", repo.FullPath)
@ -237,3 +238,58 @@ func lookupRepos(msg []byte) (*gitpb.Repos, error) {
+
+ log.Infof("repo path: %s\n", repopath)
*/
func updateRepos(msg []byte) (*gitpb.Repos, error) {
log.Info("proto.Unmarshal() try message len", len(msg))
m := gitpb.NewRepos()
if err := m.Unmarshal(msg); err != nil {
log.Info("gitpb.Repos.Unmarshal() failed. len(msg) =", len(msg), err)
return m, err
}
newpb := gitpb.NewRepos()
log.Info("GOT repos:", len(msg))
for repo := range m.IterAll() {
log.Infof("repo:%s,%s\n", repo.Namespace, repo.FullPath)
if repo.Namespace == "" {
log.Info("todo: namespace empty for", repo.FullPath)
continue
// return nil, fmt.Errorf("todo: namespace empty for " + repo.FullPath)
}
// save the git.pb files
repopath := filepath.Join("/home/forge", repo.Namespace)
if !shell.IsDir(repopath) {
if err := os.MkdirAll(repopath, os.ModePerm); err != nil {
log.Warn("mkdir fail", repo.Namespace, err)
continue
}
}
filename := filepath.Join(repopath, "git.pb")
log.Infof("update repo file %s\n", repopath)
// if !shell.Exists(filename) {
data, err := repo.Marshal()
if err != nil {
log.Info("patchsets.Marshal() to wire failed", err)
continue
}
gitpbf, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
defer gitpbf.Close()
if err != nil {
log.Info("filename open error:", filename, err)
continue
}
gitpbf.Write(data)
// }
// log.Infof("repo path: %s\n", repopath)
}
/*
// print out found git.pb files
for repo := range newpb.IterAll() {
log.Infof("updated repo:%-14s,%s\n", repo.GetMasterVersion(), repo.Namespace)
}
*/
return newpb, nil
}

12
http.go
View File

@ -45,6 +45,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if route == "/lookup" {
log.Info("doing lookup len(msg) =", len(msg))
found, err := lookupRepos(msg)
if err != nil {
return
@ -60,6 +61,17 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
if route == "/update" {
log.Info("doing update len(msg) =", len(msg))
found, err := updateRepos(msg)
if err != nil {
return
}
found.SendPB(w)
return
}
if route == "/GetPatchsets" {
doSendPatchsets(w)
return