guireleaser/http.go

144 lines
3.8 KiB
Go
Raw Normal View History

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)
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")
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-12-17 18:48:45 -06:00
// log.Info(me.current.StandardHeader())
log.Info(me.forge.StandardReleaseHeader(me.current, "todoing"))
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-12-17 18:48:45 -06:00
repo := me.forge.FindByGoPath(repoName)
if repo == nil {
2024-11-07 03:32:00 -06:00
log.Info("FindRepoByName() returned nil")
return
}
setCurrentRepo(repo, "HTTP", "doRelease() ?")
2024-11-22 21:05:09 -06:00
return
2024-12-02 10:43:48 -06:00
case "/fixNext":
2024-12-17 07:03:17 -06:00
check := me.forge.FindByGoPath(me.current.GetGoPath())
if check == nil {
2024-12-17 07:03:17 -06:00
log.Info("boo, you didn't git clone", me.current.GetGoPath())
return
}
2024-12-02 10:43:48 -06:00
// destroy and recreate the go.sum
fixGodeps(check)
2024-12-11 01:19:07 -06:00
findOk = true
2024-12-02 05:13:17 -06:00
return
case "/showNext":
2025-01-08 00:59:38 -06:00
check := me.forge.FindByGoPath(me.current.GetGoPath())
if check == nil {
log.Info("boo, current is missing", me.current.GetGoPath())
return
}
testGoRepo(check)
2025-01-08 00:59:38 -06:00
me.forge.HumanPrintRepo(check)
2024-12-02 10:43:48 -06:00
return
case "/list":
me.forge.PrintHumanTable(me.found)
2024-12-02 10:43:48 -06:00
return
case "/releaseList":
2025-01-08 00:59:38 -06:00
me.forge.PrintHumanTable(me.found)
2024-12-02 10:43:48 -06:00
return
default:
2024-11-07 05:15:54 -06:00
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!")
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
}
// starts and sits waiting for HTTP requests
func startHTTP() {
http.HandleFunc("/", okHandler)
2024-12-02 10:43:48 -06:00
p := fmt.Sprintf(":%d", argv.Port)
log.Println("Running on port", p)
2024-12-03 18:00:42 -06:00
err := http.ListenAndServe(p, nil)
if err != nil {
log.Println("Error starting server:", err)
2024-12-02 10:43:48 -06:00
}
}