144 lines
3.8 KiB
Go
144 lines
3.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
"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")
|
|
|
|
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 err := doRelease(); err == nil {
|
|
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.ScanRepositoriesOld()
|
|
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() ?")
|
|
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":
|
|
check := me.forge.FindByGoPath(me.current.GetGoPath())
|
|
if check == nil {
|
|
log.Info("boo, current is missing", me.current.GetGoPath())
|
|
return
|
|
}
|
|
testGoRepo(check)
|
|
me.forge.HumanPrintRepo(check)
|
|
return
|
|
case "/list":
|
|
me.forge.PrintHumanTable(me.found)
|
|
return
|
|
case "/releaseList":
|
|
me.forge.PrintHumanTable(me.found)
|
|
return
|
|
default:
|
|
log.Info("BAD URL = " + route)
|
|
}
|
|
}
|
|
|
|
func testGoRepo(check *gitpb.Repo) {
|
|
data, _ := os.ReadFile(filepath.Join(check.FullPath, "go.mod"))
|
|
log.Info(string(data))
|
|
|
|
if err := me.forge.FinalGoDepsCheckOk(check, true); err == nil {
|
|
log.Info("forge.FinalGoDepsCheck(check) worked!")
|
|
} else {
|
|
log.Info("forge.FinalGoDepsCheck(check) failed. boo.")
|
|
}
|
|
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|