diff options
| author | root <[email protected]> | 2025-10-02 13:02:39 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-02 15:17:10 -0500 | 
| commit | 572937b9f70943dfee8c7bc6967e54b762b4e7bf (patch) | |
| tree | f9e6b42b9ea139bc0d2d03b91dc2e41919972ae1 | |
| parent | 8d311c65a7583b0da58d2c9870301acdf93ccb0d (diff) | |
allow URL updates
| -rw-r--r-- | handleRepos.go | 23 | ||||
| -rw-r--r-- | http.go | 7 | 
2 files changed, 28 insertions, 2 deletions
diff --git a/handleRepos.go b/handleRepos.go index 20cf66c..ac28c7f 100644 --- a/handleRepos.go +++ b/handleRepos.go @@ -69,6 +69,29 @@ func checkRequest(pb *gitpb.Repos, reqPB *httppb.HttpRequest) *gitpb.Repos {  			// don't know about this  			continue  		} +		if found.GetURL() != repo.GetURL() { +			log.Infof("'%s' url %s mismatch %s\n", found.FullPath, found.GetURL(), repo.GetURL()) +		} +		checkPB.Append(found) +	} +	return checkPB +} + +func updateURLs(pb *gitpb.Repos, reqPB *httppb.HttpRequest) *gitpb.Repos { +	checkPB := gitpb.NewRepos() +	for repo := range pb.IterAll() { +		found := me.forge.Repos.FindByNamespace(repo.Namespace) +		if found == nil { +			log.Infof("found == nil namespace=%s\n", repo.Namespace) +			continue +		} +		if found.GetURL() != repo.GetURL() { +			log.Infof("'%s' url %s mismatch %s\n", found.FullPath, found.GetURL(), repo.GetURL()) +			cmd := []string{"git", "remote", "set-url", "origin", repo.GetURL()} +			found.RunVerbose(cmd) +		} else { +			// log.Infof("'%s' url %s == %s\n", found.FullPath, found.GetURL(), repo.GetURL()) +		}  		checkPB.Append(found)  	}  	return checkPB @@ -38,7 +38,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {  	if strings.HasPrefix(route, "/repos/") {  		pb := gitpb.NewRepos()  		if err := pb.Unmarshal(reqPB.ClientData); err == nil { -			reqPB.Logf("Repos Unmarshal() len=%d", pb.Len()) +			reqPB.Logf("http recieved %d repos", pb.Len())  		} else {  			reqPB.Logf("Repos Unmarshal() err=%v", err)  		} @@ -47,13 +47,16 @@ func okHandler(w http.ResponseWriter, r *http.Request) {  		case "/repos/check":  			result = checkRequest(pb, reqPB)  			reqPB.Logf("repos check result.Len()=%d pb.Len()=%d", result.Len(), pb.Len()) +		case "/repos/updateURL": +			result = updateURLs(pb, reqPB) +			reqPB.Logf("repo urls sent len=%d updated len=%d", result.Len(), pb.Len())  		case "/repos/pull":  			result = pullRequest(pb, reqPB)  		case "/repos/add":  			result = addRequest(pb, reqPB)  		default:  			reqPB.Logf("repos check result.Len()=%d pb.Len()=%d", result.Len(), pb.Len()) -			log.Info("repos", route, "unknown") +			log.Info("UNKNOWN ROUTE:", route)  		}  		if err := result.SendReply(w, reqPB); err != nil {  			reqPB.Logf("Oh well, Send to client failed. err=%v", err)  | 
