125 lines
2.7 KiB
Go
125 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
|
|
"go.wit.com/lib/gui/gowit"
|
|
"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)
|
|
|
|
if route == "/help" {
|
|
msg(w, "list/ list modified repos")
|
|
msg(w, "list?readonly=true shows every repo")
|
|
msg(w, "")
|
|
msg(w, "setBranchesToMasterB maybe this sets everything to master?")
|
|
msg(w, "doSingleRepo?repo=go.wit.com/gui attempts to release gui")
|
|
msg(w, "")
|
|
msg(w, "setVersion?repo=go.wit.com/gui?target=0.2 attempts to set the target version to 0.2")
|
|
msg(w, "")
|
|
return
|
|
}
|
|
|
|
if route == "/release" {
|
|
// simpleRelease(w, r)
|
|
return
|
|
}
|
|
|
|
if route == "/gitpull" {
|
|
return
|
|
}
|
|
|
|
if route == "/list" {
|
|
readonly := r.URL.Query().Get("readonly")
|
|
onlydirty := r.URL.Query().Get("onlydirty")
|
|
perfect := r.URL.Query().Get("perfect")
|
|
|
|
me.repos.View.PrintReport(w, readonly, onlydirty, perfect)
|
|
return
|
|
}
|
|
|
|
if route == "/findNext" {
|
|
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?")
|
|
}
|
|
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())
|
|
return
|
|
}
|
|
|
|
if route == "/releaselist" {
|
|
readonly := r.URL.Query().Get("readonly")
|
|
perfect := r.URL.Query().Get("perfect")
|
|
|
|
me.repos.View.PrintReleaseReport(w, readonly, perfect)
|
|
return
|
|
}
|
|
|
|
if route == "/goweblist" {
|
|
gowit.DumpVersions(me.repos.View)
|
|
return
|
|
}
|
|
|
|
if route == "/setBranchesToMasterB" {
|
|
msg(w, "set all branches to master")
|
|
me.Disable()
|
|
defer me.Enable()
|
|
if setAllBranchesToMaster() {
|
|
// if it succeeds, disable this button
|
|
me.setBranchesToMasterB.Disable()
|
|
}
|
|
return
|
|
}
|
|
|
|
if route == "/doSingleRepo" {
|
|
reponame := r.URL.Query().Get("repo")
|
|
msg(w, "doSingleRepo: "+reponame)
|
|
doSingleRepo(reponame)
|
|
}
|
|
|
|
if route == "/quit" {
|
|
os.Exit(0)
|
|
return
|
|
}
|
|
|
|
log.Warn("BAD URL =", route)
|
|
fmt.Fprintln(w, "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)
|
|
}
|
|
}
|