package main import ( "fmt" "net/http" "os" "path/filepath" "strings" "go.wit.com/lib/gui/repolist" "go.wit.com/log" ) // remove '?' part and trailing '/' func cleanURL(url string) string { url = "/" + strings.Trim(url, "/") return url } func okHandler(w http.ResponseWriter, r *http.Request) { var route string route = cleanURL(r.URL.Path) log.HttpMode(w) defer log.HttpMode(nil) // common http args that can be set repoName := r.URL.Query().Get("repo") version := r.URL.Query().Get("version") comment := r.URL.Query().Get("comment") readonly := r.URL.Query().Get("readonly") onlydirty := r.URL.Query().Get("onlydirty") perfect := r.URL.Query().Get("perfect") whitelist := r.URL.Query().Get("whitelist") switch route { case "/help": log.Info("list/ list modified repos") log.Info("list?readonly=true shows every repo") log.Info("") log.Info("doRelease runs doRelease()") log.Info("findNext runs findNext()") log.Info("showNext shows the repo for doRelease()") log.Info("setTargetVersion set the target version for findNext()") log.Info("setAllTargetVersions?version=v0.12.4 set ever repo to target version") log.Info("setCurrentRepo?repo=go.wit.com/gui runs setCurrentRepo(repo)") log.Info("") log.Info("setAllBranchesToMaster git checkout master on every repo") log.Info("") log.Info("setVersion?repo=go.wit.com/gui?target=0.2 attempts to set the target version to 0.2") log.Info("") case "/doRelease": buttonDisable() if doRelease() { buttonEnable() log.Info("doRelease() worked") } else { log.Info("doRelease() failed") } case "/findNext": me.Disable() defer me.Enable() if findNext() { log.Info("findNext() found a repo") } else { log.Info("findNext() did not find a repo. You might be finished?") } log.Info("repo: " + me.release.repo.String()) log.Info("name: " + me.release.version.String()) log.Info("notes: " + me.release.notes.String()) log.Info("status: " + me.release.status.String()) if me.current == nil { log.Info("findNext() == nil") return } log.Info(me.current.StandardHeader()) log.Info(me.current.StandardReleaseHeader()) case "/rescanAll": me.repos.View.ScanRepositories() case "/setCurrentRepo": log.Info("repo: " + repoName) log.Info("version: " + version) log.Info("comment: " + comment) repo := me.repos.View.FindByName(repoName) if repo == nil { log.Info("FindRepoByName() returned nil") return } setCurrentRepo(repo, "HTTP", "doRelease() ?") case "/IncrementRevisonVersion": log.Info("repo: " + repoName) log.Info("version: " + version) me.current.Status.IncrementRevisionVersion(comment) case "/IncrementMinorVersion": log.Info("repo: " + repoName) log.Info("version: " + version) me.current.Status.IncrementMinorVersion("trying minor") case "/setAllBranchesToMaster": log.Info("set all branches to master") me.Disable() defer me.Enable() if setAllBranchesToMaster() { // if it succeeds, disable this button me.setBranchesToMasterB.Disable() } return case "/setTargetVersion": log.Info("repo: " + repoName) log.Info("version: " + version) if repoName != "" { repo := me.repos.View.FindByName(repoName) if repo == nil { log.Info("could not find repo", repoName) } else { log.Info("setting target version", version) repo.Status.SetTargetVersion(version) } return } if me.current == nil { log.Info("me.current == nil") return } me.current.Status.SetTargetVersion(version) return case "/setAllTargetVersions": log.Info("version: " + version) loop := me.repos.View.ReposSortByName() for loop.Scan() { repo := loop.Repo() master := repo.Status.GetMasterVersion() lastTag := repo.Status.LastTag() if master == lastTag { repo.Status.SetTargetVersion(master) } else { repo.Status.IncrementRevisionVersion("Nov 2024 test") } } case "/whitelist": repo := me.repos.View.FindByName(repoName) if repo == nil { log.Info("FindRepoByName() returned nil") return } log.Info("whitelisted " + repo.Name()) if whitelist == "false" { repo.Status.Whitelist = false } else { repo.Status.Whitelist = true } case "/testNext": testNext() return case "/fixNext": check := me.forge.Repos.FindByGoPath(me.current.GoPath()) if check == nil { log.Info("boo, you didn't git clone", me.current.GoPath()) return } // destroy and recreate the go.sum fixGodeps(check) return case "/showNext": showNext() return case "/list": PrintReport(readonly, onlydirty, perfect) return case "/releaseList": PrintReleaseReport(readonly, perfect) return case "/quit": log.Info("Got URL /quit") os.Exit(0) return case "/goweblist": loop := me.repos.View.ReposAll() for loop.Scan() { repo := loop.Repo() lastTag := repo.LastTag() tag := repo.Status.NewestTag() gitAge, err := tag.GetDate() if err != nil { log.Info(fmt.Sprintf("tag date error", repo.Name())) } // if lastTag == "" { // lastTag = tag.Name() // } if repo.ReadOnly() { if readonly == "true" { continue } } // dur := time.Since(gitAge) // log.Info(fmt.Sprintf("%-60s %s %s %s", repo.Name(), lastTag, shell.FormatDuration(dur), lastTag, tag.Name())) log.Info(fmt.Sprintf("%s %d %s", repo.Name(), gitAge.Unix(), lastTag)) /* for _, tag := range repo.Tags.ListAll() { log.Info(fmt.Sprintf("%-60s %s", "", tag.Name())) } */ } return default: log.Info("BAD URL = " + route) } } // starts and sits waiting for HTTP requests func startHTTP() { http.HandleFunc("/", okHandler) p := fmt.Sprintf(":%d", argv.Port) log.Println("Running on port", p) err := http.ListenAndServe(p, nil) if err != nil { log.Println("Error starting server:", err) } } func testNext() { // re-scans the go.sum file. DOES NOT MODIFY ANYTHING check := me.forge.Repos.FindByGoPath(me.current.GoPath()) if check == nil { log.Info("boo, you didn't git clone", me.current.GoPath()) return } data, _ := os.ReadFile(filepath.Join(check.FullPath, "go.mod")) log.Info(string(data)) if me.forge.FinalGoDepsCheckOk(check) { log.Info("forge.FinalGoDepsCheck(check) worked!") } else { log.Info("forge.FinalGoDepsCheck(check) failed. boo.") } } func showNext() { log.Info("gui repo: " + me.release.repo.String()) log.Info("gui name: " + me.release.version.String()) log.Info("gui notes: " + me.release.notes.String()) log.Info("gui status: " + me.release.status.String()) log.Info("") if me.current == nil { log.Info("me.current == nil") return } if me.current.Status.IsReleased() { log.Info("IsReleased() == true SHOULD NOT RELEASE THIS") } else { log.Info("IsReleased() == false") } if me.current.Status.CheckDirty() { log.Info("CheckDirty() == true. SHOULD NOT RELEASE THIS") } else { log.Info("CheckDirty() == false") } if me.current.Status.IsPrimitive() { log.Info("IsPrimitive() == true") } else { log.Info("IsPrimitive() == false") } if me.current.Status.IsPrivate() { log.Info("IsPrivate() == true") } else { log.Info("IsPrivate() == false") } if ok, compiled, err := me.current.IsProtobuf(); ok { log.Info(log.Sprint("IsProtobuf() == true compiled protobuf files = ", compiled)) if err != nil { log.Info(log.Sprint("IsProtobuf() == err", err)) os.Exit(-1) } for _, s := range compiled { log.Info("\tcompiled file found:", s) } } else { log.Info("IsProtobuf() == false") if err != nil { log.Info(log.Sprint("IsProtobuf() == err", err)) } } if me.current.Status.Whitelist { log.Info("Whitelist == true SHOULD NOT RELEASE THIS") } else { log.Info("Whitelist == false") } log.Info("") testNext() log.Info(repolist.ReportHeader()) log.Info(me.current.StandardHeader()) log.Info("") log.Info(repolist.ReleaseReportHeader()) log.Info(me.current.StandardReleaseHeader()) }