279 lines
7.1 KiB
Go
279 lines
7.1 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"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")
|
|
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.forge.StandardReleaseHeader(me.current, "todoing"))
|
|
case "/rescanAll":
|
|
me.repos.View.ScanRepositories()
|
|
case "/setCurrentRepo":
|
|
|
|
log.Info("repo: " + repoName)
|
|
log.Info("version: " + version)
|
|
log.Info("comment: " + comment)
|
|
|
|
repo := me.forge.FindByGoPath(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.IncrementTargetRevision()
|
|
case "/IncrementMinorVersion":
|
|
log.Info("repo: " + repoName)
|
|
log.Info("version: " + version)
|
|
|
|
me.current.IncrementTargetMinor()
|
|
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.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.FindByGoPath(me.current.GetGoPath())
|
|
if check == nil {
|
|
log.Info("boo, you didn't git clone", me.current.GetGoPath())
|
|
return
|
|
}
|
|
// destroy and recreate the go.sum
|
|
fixGodeps(check)
|
|
findOk = true
|
|
return
|
|
case "/showNext":
|
|
showNext()
|
|
return
|
|
case "/list":
|
|
me.forge.PrintReleaseReport(me.forge.Repos)
|
|
return
|
|
case "/releaseList":
|
|
me.forge.PrintReleaseReport(me.found)
|
|
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.FindByGoPath(me.current.GetGoPath())
|
|
if check == nil {
|
|
log.Info("boo, you didn't git clone", me.current.GetGoPath())
|
|
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
|
|
}
|
|
|
|
check := me.forge.FindByGoPath(me.current.GetGoPath())
|
|
if check == nil {
|
|
log.Info("forge: how was this not found?", me.current.GetGoPath())
|
|
return
|
|
}
|
|
|
|
if me.current.GetTargetVersion() == "" {
|
|
log.Info("TargetVersion == blank")
|
|
}
|
|
if me.current.GetTargetVersion() == me.current.GetCurrentVersion() {
|
|
log.Info("IsReleased() == true. do not release this a second time")
|
|
} else {
|
|
log.Info("IsReleased() == false")
|
|
}
|
|
if check.CheckDirty() {
|
|
log.Info("CheckDirty() == true. do not release dirty repos")
|
|
} else {
|
|
log.Info("CheckDirty() == false")
|
|
}
|
|
if check.GetGoPrimitive() {
|
|
log.Info("IsPrimitive() == true")
|
|
} else {
|
|
log.Info("IsPrimitive() == false")
|
|
}
|
|
if me.forge.Config.IsPrivate(check.GetGoPath()) {
|
|
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 {
|
|
msg := fmt.Sprint("IsProtobuf() == err", err)
|
|
badExit(errors.New(msg))
|
|
}
|
|
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))
|
|
}
|
|
}
|
|
|
|
testNext()
|
|
|
|
log.Info(repolist.ReportHeader())
|
|
log.Info("")
|
|
log.Info(repolist.ReleaseReportHeader())
|
|
log.Info(me.forge.StandardReleaseHeader(me.current, "notsure"))
|
|
}
|