// Copyright 2017-2025 WIT.COM Inc. All rights reserved. // Use of this source code is governed by the GPL 3.0 package main import ( "strings" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func updateURL(repo *gitpb.Repo) bool { found := me.forge.Repos.FindByNamespace(repo.Namespace) if found == nil { return false } if repo.URL == found.URL { return false } cmd := []string{"git", "remote", "set-url", "origin", repo.URL} found.URL = repo.URL if argv.Fix { log.Infof("%s update URL to %v\n", found.URL, cmd) found.Run(cmd) return true } log.Infof("add --fix to update %s with %v\n", found.URL, cmd) return true } func doFixUrls() error { submit := me.forge.PrepareCheckRepos() updatepb, regPB, err := submit.HttpPost(myServer(), "check") if err != nil { log.Info("err =", err) } if regPB == nil { log.Info("regPB==nil") } if updatepb == nil { log.Info("server sent nil back") return err } var count int // log.Infof("pull check %s pb.Len()=%d client.Len()=%d server.Len()=%d err=%v\n", regPB.URL, updatepb.Len(), regPB.ClientDataLen, regPB.ServerDataLen, err) log.Infof("pull check pb.Len()=%d\n", updatepb.Len()) updatecheck := gitpb.NewRepos() for repo := range updatepb.IterAll() { if updateURL(repo) { count += 1 } if repo.Namespace == "" { log.Info("forge sent back empty namespace", repo) continue } found := me.forge.Repos.FindByNamespace(repo.Namespace) if found == nil { log.Info("you don't have namespace?", repo.Namespace) continue } if !strings.HasPrefix(found.Namespace, "go.wit.com") { continue } updatecheck.Append(repo) // spew.Dump(repo) // me.sh.GoodExit("") /* found, _ := needToUpdateRepo(repo) if found == nil { continue } if !argv.Force { continue } // found.RunVerbose([]string{"git", "pull", "origin", found.GetMasterBranchName()}) found.CheckoutMaster() found.GitPull() found.ReloadCheck() found.GitPull() if count > 10 { break } count += 1 */ } footer := me.forge.PrintPullTable(updatecheck) log.Info("These repos have broken URLs. Fix them with --fix", footer) return nil }