2024-11-04 08:16:42 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2024-11-05 04:46:59 -06:00
|
|
|
"go.wit.com/lib/gui/repolist"
|
2024-11-04 08:16:42 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// remove '?' part and trailing '/'
|
|
|
|
func cleanURL(url string) string {
|
|
|
|
url = "/" + strings.Trim(url, "/")
|
|
|
|
return url
|
|
|
|
}
|
|
|
|
|
|
|
|
// send stuff to the socket and stdout
|
|
|
|
func msg(w http.ResponseWriter, s string) {
|
|
|
|
log.Info(s)
|
|
|
|
fmt.Fprintln(w, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func okHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var route string
|
|
|
|
route = cleanURL(r.URL.Path)
|
|
|
|
|
2024-11-05 03:17:40 -06:00
|
|
|
// 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")
|
|
|
|
|
2024-11-05 01:44:24 -06:00
|
|
|
switch route {
|
|
|
|
case "/help":
|
2024-11-04 08:16:42 -06:00
|
|
|
msg(w, "list/ list modified repos")
|
|
|
|
msg(w, "list?readonly=true shows every repo")
|
|
|
|
msg(w, "")
|
2024-11-05 01:44:24 -06:00
|
|
|
msg(w, "doRelease runs doRelease()")
|
|
|
|
msg(w, "findNext runs findNext()")
|
|
|
|
msg(w, "showNext shows the repo for doRelease()")
|
|
|
|
msg(w, "setTargetVersion set the target version for findNext()")
|
|
|
|
msg(w, "setAllTargetVersions?version=v0.12.4 set ever repo to target version")
|
|
|
|
msg(w, "setCurrentRepo?repo=go.wit.com/gui runs setCurrentRepo(repo)")
|
|
|
|
msg(w, "")
|
|
|
|
msg(w, "setAllBranchesToMaster git checkout master on every repo")
|
2024-11-04 08:16:42 -06:00
|
|
|
msg(w, "")
|
|
|
|
msg(w, "setVersion?repo=go.wit.com/gui?target=0.2 attempts to set the target version to 0.2")
|
|
|
|
msg(w, "")
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/tempWin":
|
|
|
|
tempWin := makeTempView()
|
|
|
|
|
|
|
|
loop := me.repos.View.UnmergedRepos()
|
|
|
|
for loop.Scan() {
|
|
|
|
repo := loop.Repo()
|
|
|
|
tempWin.View.ShowRepo(repo)
|
2024-11-05 03:17:40 -06:00
|
|
|
msg(w, "UnmergedRepo: "+repo.Name())
|
2024-11-05 01:44:24 -06:00
|
|
|
}
|
|
|
|
case "/doRelease":
|
|
|
|
buttonDisable()
|
|
|
|
if doRelease() {
|
|
|
|
buttonEnable()
|
|
|
|
msg(w, "doRelease() worked")
|
|
|
|
} else {
|
|
|
|
msg(w, "doRelease() failed")
|
|
|
|
}
|
|
|
|
case "/findNext":
|
2024-11-04 08:16:42 -06:00
|
|
|
me.Disable()
|
|
|
|
defer me.Enable()
|
|
|
|
if findNext() {
|
|
|
|
msg(w, "findNext() found a repo")
|
|
|
|
} else {
|
|
|
|
msg(w, "findNext() did not find a repo. You might be finished?")
|
|
|
|
}
|
2024-11-04 13:24:46 -06:00
|
|
|
msg(w, "repo: "+me.release.repo.String())
|
|
|
|
msg(w, "name: "+me.release.version.String())
|
|
|
|
msg(w, "notes: "+me.release.notes.String())
|
|
|
|
msg(w, "status: "+me.release.status.String())
|
|
|
|
|
|
|
|
msg(w, me.current.StandardHeader())
|
|
|
|
msg(w, me.current.StandardReleaseHeader())
|
2024-11-05 04:46:59 -06:00
|
|
|
case "/rescanAll":
|
|
|
|
me.repos.View.ScanRepositories()
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/setCurrentRepo":
|
2024-11-04 13:24:46 -06:00
|
|
|
|
|
|
|
msg(w, "repo: "+repoName)
|
|
|
|
msg(w, "version: "+version)
|
|
|
|
msg(w, "comment: "+comment)
|
|
|
|
|
2024-11-05 01:44:24 -06:00
|
|
|
repo := me.repos.View.FindRepoByName(repoName)
|
|
|
|
if repo == nil {
|
|
|
|
msg(w, "FindRepoByName() returned nil")
|
|
|
|
return
|
|
|
|
}
|
2024-11-04 13:24:46 -06:00
|
|
|
|
|
|
|
setCurrentRepo(repo, "HTTP", "doRelease() ?")
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/IncrementRevisonVersion":
|
2024-11-05 03:17:40 -06:00
|
|
|
msg(w, "repo: "+repoName)
|
2024-11-04 13:24:46 -06:00
|
|
|
msg(w, "version: "+version)
|
|
|
|
me.current.Status.IncrementRevisionVersion(comment)
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/IncrementMinorVersion":
|
2024-11-05 03:17:40 -06:00
|
|
|
msg(w, "repo: "+repoName)
|
2024-11-04 13:24:46 -06:00
|
|
|
msg(w, "version: "+version)
|
|
|
|
|
|
|
|
me.current.Status.IncrementMinorVersion("trying minor")
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/setAllBranchesToMaster":
|
|
|
|
msg(w, "set all branches to master")
|
|
|
|
me.Disable()
|
|
|
|
defer me.Enable()
|
|
|
|
if setAllBranchesToMaster() {
|
|
|
|
// if it succeeds, disable this button
|
|
|
|
me.setBranchesToMasterB.Disable()
|
|
|
|
}
|
2024-11-04 13:24:46 -06:00
|
|
|
return
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/setTargetVersion":
|
2024-11-05 03:17:40 -06:00
|
|
|
msg(w, "repo: "+repoName)
|
2024-11-04 13:24:46 -06:00
|
|
|
msg(w, "version: "+version)
|
2024-11-05 01:44:24 -06:00
|
|
|
if me.current == nil {
|
|
|
|
msg(w, "me.current == nil")
|
|
|
|
return
|
|
|
|
}
|
2024-11-04 13:24:46 -06:00
|
|
|
me.current.Status.SetTargetVersion(version)
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/setAllTargetVersions":
|
|
|
|
msg(w, "version: "+version)
|
2024-11-04 13:24:46 -06:00
|
|
|
|
2024-11-05 01:44:24 -06:00
|
|
|
loop := me.repos.View.ReposSortByName()
|
|
|
|
for loop.Scan() {
|
|
|
|
repo := loop.Repo()
|
|
|
|
|
|
|
|
master := repo.Status.GetMasterVersion()
|
2024-11-05 03:17:40 -06:00
|
|
|
lastTag := repo.Status.LastTag()
|
|
|
|
if master == lastTag {
|
|
|
|
repo.Status.SetTargetVersion(master)
|
2024-11-05 01:44:24 -06:00
|
|
|
} else {
|
|
|
|
repo.Status.IncrementRevisionVersion("Nov 2024 test")
|
|
|
|
}
|
|
|
|
}
|
2024-11-05 03:17:40 -06:00
|
|
|
case "/whitelist":
|
|
|
|
repo := me.repos.View.FindRepoByName(repoName)
|
|
|
|
if repo == nil {
|
|
|
|
msg(w, "FindRepoByName() returned nil")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
msg(w, "whitelisted "+repo.Name())
|
|
|
|
if whitelist == "false" {
|
|
|
|
repo.Status.Whitelist = false
|
|
|
|
} else {
|
|
|
|
repo.Status.Whitelist = true
|
|
|
|
}
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/showNext":
|
|
|
|
msg(w, "gui repo: "+me.release.repo.String())
|
|
|
|
msg(w, "gui name: "+me.release.version.String())
|
|
|
|
msg(w, "gui notes: "+me.release.notes.String())
|
|
|
|
msg(w, "gui status: "+me.release.status.String())
|
|
|
|
msg(w, "")
|
2024-11-04 13:24:46 -06:00
|
|
|
|
|
|
|
if checkValidGoSum(me.current) {
|
|
|
|
msg(w, "checkValidGoSum() == true")
|
|
|
|
} else {
|
2024-11-05 04:46:59 -06:00
|
|
|
msg(w, "checkValidGoSum() == false SHOULD NOT RELEASE THIS")
|
2024-11-04 13:24:46 -06:00
|
|
|
}
|
2024-11-05 01:44:24 -06:00
|
|
|
if me.current.Status.IsReleased() {
|
2024-11-05 04:46:59 -06:00
|
|
|
msg(w, "IsReleased() == true SHOULD NOT RELEASE THIS")
|
2024-11-05 01:44:24 -06:00
|
|
|
} else {
|
|
|
|
msg(w, "IsReleased() == false")
|
|
|
|
}
|
2024-11-05 04:46:59 -06:00
|
|
|
if me.current.Status.CheckDirty() {
|
|
|
|
msg(w, "CheckDirty() == true. SHOULD NOT RELEASE THIS")
|
|
|
|
} else {
|
|
|
|
msg(w, "CheckDirty() == false")
|
|
|
|
}
|
|
|
|
if me.current.Status.IsPrimitive() {
|
|
|
|
msg(w, "IsPrimitive() == true")
|
|
|
|
} else {
|
|
|
|
msg(w, "IsPrimitive() == false")
|
|
|
|
}
|
|
|
|
if me.current.Status.IsProtobuf() {
|
|
|
|
msg(w, "IsProtobuf() == true")
|
|
|
|
} else {
|
|
|
|
msg(w, "IsProtobuf() == false")
|
|
|
|
}
|
|
|
|
if me.current.Status.Whitelist {
|
|
|
|
msg(w, "Whitelist == true SHOULD NOT RELEASE THIS")
|
|
|
|
} else {
|
|
|
|
msg(w, "Whitelist == false")
|
|
|
|
}
|
2024-11-05 01:44:24 -06:00
|
|
|
msg(w, "")
|
|
|
|
|
2024-11-05 04:46:59 -06:00
|
|
|
msg(w, repolist.ReportHeader())
|
2024-11-04 13:24:46 -06:00
|
|
|
msg(w, me.current.StandardHeader())
|
2024-11-05 04:46:59 -06:00
|
|
|
msg(w, "")
|
|
|
|
msg(w, repolist.ReleaseReportHeader())
|
2024-11-04 13:24:46 -06:00
|
|
|
msg(w, me.current.StandardReleaseHeader())
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/list":
|
|
|
|
me.repos.View.PrintReport(w, readonly, onlydirty, perfect)
|
|
|
|
case "/releaseList":
|
2024-11-04 08:16:42 -06:00
|
|
|
me.repos.View.PrintReleaseReport(w, readonly, perfect)
|
2024-11-05 01:44:24 -06:00
|
|
|
case "/quit":
|
|
|
|
msg(w, "Got URL /quit")
|
2024-11-04 08:16:42 -06:00
|
|
|
os.Exit(0)
|
2024-11-05 04:46:59 -06:00
|
|
|
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 {
|
|
|
|
msg(w, fmt.Sprintf("tag date error", repo.Name()))
|
|
|
|
}
|
|
|
|
// if lastTag == "" {
|
|
|
|
// lastTag = tag.Name()
|
|
|
|
// }
|
|
|
|
if repo.ReadOnly() {
|
|
|
|
if readonly == "true" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// dur := time.Since(gitAge)
|
|
|
|
// msg(w, fmt.Sprintf("%-60s %s %s %s", repo.Name(), lastTag, shell.FormatDuration(dur), lastTag, tag.Name()))
|
|
|
|
msg(w, fmt.Sprintf("%s %d %s", repo.Name(), gitAge.Unix(), lastTag))
|
|
|
|
/*
|
|
|
|
for _, tag := range repo.Tags.ListAll() {
|
|
|
|
msg(w, fmt.Sprintf("%-60s %s", "", tag.Name()))
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
2024-11-05 01:44:24 -06:00
|
|
|
default:
|
|
|
|
msg(w, "BAD URL = "+route)
|
2024-11-04 08:16:42 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|