guireleaser/http.go

312 lines
8.0 KiB
Go
Raw Normal View History

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)
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 "/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
}
2024-12-02 05:13:17 -06:00
case "/testNext":
2024-12-02 10:43:48 -06:00
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
}
2024-12-02 10:43:48 -06:00
// destroy and recreate the go.sum
fixGodeps(check)
2024-12-02 05:13:17 -06:00
return
case "/showNext":
2024-12-02 10:43:48 -06:00
showNext()
return
case "/list":
PrintReport(readonly, onlydirty, perfect)
2024-12-02 10:43:48 -06:00
return
case "/releaseList":
PrintReleaseReport(readonly, perfect)
2024-12-02 10:43:48 -06:00
return
case "/quit":
2024-11-07 03:32:00 -06:00
log.Info("Got URL /quit")
os.Exit(0)
2024-12-02 10:43:48 -06:00
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 {
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()))
}
*/
}
2024-12-02 10:43:48 -06:00
return
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)
2024-12-02 08:45:13 -06:00
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)
}
}
2024-12-02 10:43:48 -06:00
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))
2024-12-02 10:43:48 -06:00
if me.forge.FinalGoDepsCheckOk(check) {
log.Info("forge.FinalGoDepsCheck(check) worked!")
2024-12-02 10:43:48 -06:00
} else {
log.Info("forge.FinalGoDepsCheck(check) failed. boo.")
2024-12-02 10:43:48 -06:00
}
2024-12-02 10:43:48 -06:00
}
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()
2024-12-02 10:43:48 -06:00
log.Info(repolist.ReportHeader())
log.Info(me.current.StandardHeader())
log.Info("")
log.Info(repolist.ReleaseReportHeader())
log.Info(me.current.StandardReleaseHeader())
}