guireleaser/http.go

283 lines
7.6 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"net/http"
"os"
"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)
2024-11-07 01:25:12 -06:00
log.HttpMode(w)
2024-11-07 01:39:26 -06:00
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":
2024-11-07 03:32:00 -06:00
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 "/tempWin":
tempWin := makeTempView()
loop := me.repos.View.UnmergedRepos()
for loop.Scan() {
repo := loop.Repo()
tempWin.View.ShowRepo(repo)
2024-11-07 05:15:54 -06:00
log.Info("UnmergedRepo: " + repo.Name())
}
case "/doRelease":
buttonDisable()
2024-11-07 05:15:54 -06:00
if doRelease() {
buttonEnable()
2024-11-07 03:32:00 -06:00
log.Info("doRelease() worked")
} else {
2024-11-07 03:32:00 -06:00
log.Info("doRelease() failed")
}
case "/findNext":
me.Disable()
defer me.Enable()
if findNext() {
2024-11-07 03:32:00 -06:00
log.Info("findNext() found a repo")
} else {
2024-11-07 03:32:00 -06:00
log.Info("findNext() did not find a repo. You might be finished?")
}
2024-11-07 05:15:54 -06:00
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 {
2024-11-07 03:32:00 -06:00
log.Info("findNext() == nil")
return
}
2024-11-07 03:32:00 -06:00
log.Info(me.current.StandardHeader())
log.Info(me.current.StandardReleaseHeader())
case "/rescanAll":
me.repos.View.ScanRepositories()
case "/setCurrentRepo":
2024-11-07 05:15:54 -06:00
log.Info("repo: " + repoName)
log.Info("version: " + version)
log.Info("comment: " + comment)
2024-11-22 21:05:09 -06:00
repo := me.repos.View.FindByName(repoName)
if repo == nil {
2024-11-07 03:32:00 -06:00
log.Info("FindRepoByName() returned nil")
return
}
setCurrentRepo(repo, "HTTP", "doRelease() ?")
case "/IncrementRevisonVersion":
2024-11-07 05:15:54 -06:00
log.Info("repo: " + repoName)
log.Info("version: " + version)
me.current.Status.IncrementRevisionVersion(comment)
case "/IncrementMinorVersion":
2024-11-07 05:15:54 -06:00
log.Info("repo: " + repoName)
log.Info("version: " + version)
me.current.Status.IncrementMinorVersion("trying minor")
case "/setAllBranchesToMaster":
2024-11-07 03:32:00 -06:00
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":
2024-11-07 05:15:54 -06:00
log.Info("repo: " + repoName)
log.Info("version: " + version)
2024-11-22 21:05:09 -06:00
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 {
2024-11-07 03:32:00 -06:00
log.Info("me.current == nil")
return
}
me.current.Status.SetTargetVersion(version)
2024-11-22 21:05:09 -06:00
return
case "/setAllTargetVersions":
2024-11-07 05:15:54 -06:00
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":
2024-11-22 21:05:09 -06:00
repo := me.repos.View.FindByName(repoName)
if repo == nil {
2024-11-07 03:32:00 -06:00
log.Info("FindRepoByName() returned nil")
return
}
2024-11-07 05:15:54 -06:00
log.Info("whitelisted " + repo.Name())
if whitelist == "false" {
repo.Status.Whitelist = false
} else {
repo.Status.Whitelist = true
}
case "/showNext":
2024-11-07 05:15:54 -06:00
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())
2024-11-07 03:32:00 -06:00
log.Info("")
if me.current == nil {
2024-11-07 03:32:00 -06:00
log.Info("me.current == nil")
return
}
if checkValidGoSum(me.current) {
2024-11-07 03:32:00 -06:00
log.Info("checkValidGoSum() == true")
} else {
2024-11-07 03:32:00 -06:00
log.Info("checkValidGoSum() == false SHOULD NOT RELEASE THIS")
}
if me.current.Status.IsReleased() {
2024-11-07 03:32:00 -06:00
log.Info("IsReleased() == true SHOULD NOT RELEASE THIS")
} else {
2024-11-07 03:32:00 -06:00
log.Info("IsReleased() == false")
}
if me.current.Status.CheckDirty() {
2024-11-07 03:32:00 -06:00
log.Info("CheckDirty() == true. SHOULD NOT RELEASE THIS")
} else {
2024-11-07 03:32:00 -06:00
log.Info("CheckDirty() == false")
}
if me.current.Status.IsPrimitive() {
2024-11-07 03:32:00 -06:00
log.Info("IsPrimitive() == true")
} else {
2024-11-07 03:32:00 -06:00
log.Info("IsPrimitive() == false")
}
if me.current.Status.IsPrivate() {
log.Info("IsPrivate() == true")
} else {
log.Info("IsPrivate() == false")
}
if ok, compiled, err := me.current.Status.IsProtobuf(); ok {
2024-11-07 03:32:00 -06:00
log.Info(log.Sprint("IsProtobuf() == true compiled protobuf files = ", compiled))
if err != nil {
2024-11-07 03:32:00 -06:00
log.Info(log.Sprint("IsProtobuf() == err", err))
os.Exit(-1)
}
for _, s := range compiled {
log.Info("\tcompiled file found:", s)
}
} else {
2024-11-07 03:32:00 -06:00
log.Info("IsProtobuf() == false")
if err != nil {
log.Info(log.Sprint("IsProtobuf() == err", err))
}
}
if me.current.Status.Whitelist {
2024-11-07 03:32:00 -06:00
log.Info("Whitelist == true SHOULD NOT RELEASE THIS")
} else {
2024-11-07 03:32:00 -06:00
log.Info("Whitelist == false")
}
2024-11-07 03:32:00 -06:00
log.Info("")
2024-11-07 03:32:00 -06:00
log.Info(repolist.ReportHeader())
log.Info(me.current.StandardHeader())
log.Info("")
log.Info(repolist.ReleaseReportHeader())
log.Info(me.current.StandardReleaseHeader())
case "/list":
2024-11-07 05:15:54 -06:00
me.repos.View.PrintReport(readonly, onlydirty, perfect)
case "/releaseList":
2024-11-07 05:15:54 -06:00
me.repos.View.PrintReleaseReport(readonly, perfect)
case "/quit":
2024-11-07 03:32:00 -06:00
log.Info("Got URL /quit")
os.Exit(0)
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 {
2024-11-07 03:32:00 -06:00
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)
2024-11-07 03:32:00 -06:00
// 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() {
2024-11-07 03:32:00 -06:00
log.Info(fmt.Sprintf("%-60s %s", "", tag.Name()))
}
*/
}
default:
2024-11-07 05:15:54 -06:00
log.Info("BAD URL = " + route)
}
}
// starts and sits waiting for HTTP requests
func startHTTP() {
http.HandleFunc("/", okHandler)
p := fmt.Sprintf(":%d", myargs.Port)
log.Println("Running on port", p)
err := http.ListenAndServe(p, nil)
if err != nil {
log.Println("Error starting server:", err)
}
}