use 'http stdout' via 'log' pkg
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
bfe7180748
commit
b33280b869
70
http.go
70
http.go
|
@ -17,38 +17,34 @@ func cleanURL(url string) string {
|
||||||
return 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) {
|
func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
var route string
|
var route string
|
||||||
route = cleanURL(r.URL.Path)
|
route = cleanURL(r.URL.Path)
|
||||||
|
log.HttpMode(w)
|
||||||
|
defer log.HttpMode(nil)
|
||||||
|
|
||||||
if route == "/help" {
|
if route == "/help" {
|
||||||
msg(w, "uptime/ uptime uptime fun!")
|
log.Info("uptime/ uptime uptime fun!")
|
||||||
msg(w, "list/ list modified repos")
|
log.Info("list/ list modified repos")
|
||||||
msg(w, "list?readonly=true shows every repo")
|
log.Info("list?readonly=true shows every repo")
|
||||||
msg(w, "gitpull/ run a git pull in each repo")
|
log.Info("gitpull/ run a git pull in each repo")
|
||||||
|
|
||||||
msg(w, "")
|
log.Info("")
|
||||||
msg(w, "Examples:")
|
log.Info("Examples:")
|
||||||
msg(w, "")
|
log.Info("")
|
||||||
msg(w, "not done yet:")
|
log.Info("not done yet:")
|
||||||
|
|
||||||
msg(w, "changes/ show latest changes")
|
log.Info("changes/ show latest changes")
|
||||||
msg(w, "repo?repo=go.wit.com/apps/autotypist show this repo")
|
log.Info("repo?repo=go.wit.com/apps/autotypist show this repo")
|
||||||
msg(w, "clone?repo=go.wit.com/apps/virtigo go-clone a new repo")
|
log.Info("clone?repo=go.wit.com/apps/virtigo go-clone a new repo")
|
||||||
msg(w, "build?repo=go.wit.com/apps/autotypist build the autotypist")
|
log.Info("build?repo=go.wit.com/apps/autotypist build the autotypist")
|
||||||
msg(w, "debian?repo=go.wit.com/apps/autotypist make a debian package of the autotypist")
|
log.Info("debian?repo=go.wit.com/apps/autotypist make a debian package of the autotypist")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/uptime" {
|
if route == "/uptime" {
|
||||||
s := "uptime uptime uptime fun!"
|
s := "uptime uptime uptime fun!"
|
||||||
msg(w, s)
|
log.Info(s)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,12 +61,12 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
cmd := []string{"go-clone", repoName}
|
cmd := []string{"go-clone", repoName}
|
||||||
header := repo.StandardHeader()
|
header := repo.StandardHeader()
|
||||||
msg(w, header+strings.Join(cmd, " "))
|
log.Info(header + strings.Join(cmd, " "))
|
||||||
shell.RunHttpOut(cmd, w, r)
|
shell.RunHttpOut(cmd, w, r)
|
||||||
} else {
|
} else {
|
||||||
cmd := []string{"git", "pull", "-v"}
|
cmd := []string{"git", "pull", "-v"}
|
||||||
header := repo.StandardHeader()
|
header := repo.StandardHeader()
|
||||||
msg(w, header+strings.Join(cmd, " "))
|
log.Info(header + strings.Join(cmd, " "))
|
||||||
shell.RunPathHttpOut(repo.Status.FullPath(), cmd, w, r)
|
shell.RunPathHttpOut(repo.Status.FullPath(), cmd, w, r)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -82,10 +78,10 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
cmd := []string{"git", "pull", "-v"}
|
cmd := []string{"git", "pull", "-v"}
|
||||||
header := repo.StandardHeader()
|
header := repo.StandardHeader()
|
||||||
if repo.CheckDirty() {
|
if repo.CheckDirty() {
|
||||||
msg(w, header+"skip dirty repo")
|
log.Info(header + "skip dirty repo")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
msg(w, header+strings.Join(cmd, " "))
|
log.Info(header + strings.Join(cmd, " "))
|
||||||
shell.RunPathHttpOut(repo.Status.FullPath(), cmd, w, r)
|
shell.RunPathHttpOut(repo.Status.FullPath(), cmd, w, r)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -105,14 +101,14 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
header := repo.StandardHeader()
|
header := repo.StandardHeader()
|
||||||
if onlydirty == "true" {
|
if onlydirty == "true" {
|
||||||
if repo.CheckDirty() {
|
if repo.CheckDirty() {
|
||||||
msg(w, header+"")
|
log.Info(header + "")
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.ReadOnly() {
|
if repo.ReadOnly() {
|
||||||
if readonly == "true" {
|
if readonly == "true" {
|
||||||
msg(w, header+"readonly")
|
log.Info(header + "readonly")
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -122,16 +118,16 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if repo.State() != "merge to main" {
|
if repo.State() != "merge to main" {
|
||||||
msg(w, header+"")
|
log.Info(header + "")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if repo.CheckDirty() {
|
if repo.CheckDirty() {
|
||||||
msg(w, header+"")
|
log.Info(header + "")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
msg(w, header+"")
|
log.Info(header + "")
|
||||||
}
|
}
|
||||||
msg(w, fmt.Sprintf("EVERYTHING WORKED repo count = %d", count))
|
log.Info(fmt.Sprintf("EVERYTHING WORKED repo count = %d", count))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if route == "/goweblist" {
|
if route == "/goweblist" {
|
||||||
|
@ -143,7 +139,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
tag := repo.Status.NewestTag()
|
tag := repo.Status.NewestTag()
|
||||||
gitAge, err := tag.GetDate()
|
gitAge, err := tag.GetDate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg(w, fmt.Sprintf("tag date error", repo.Name()))
|
log.Info(fmt.Sprintf("tag date error", repo.Name()))
|
||||||
}
|
}
|
||||||
// if lastTag == "" {
|
// if lastTag == "" {
|
||||||
// lastTag = tag.Name()
|
// lastTag = tag.Name()
|
||||||
|
@ -154,11 +150,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// dur := time.Since(gitAge)
|
// dur := time.Since(gitAge)
|
||||||
// msg(w, fmt.Sprintf("%-60s %s %s %s", repo.Name(), lastTag, shell.FormatDuration(dur), lastTag, tag.Name()))
|
// log.Info(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))
|
log.Info(fmt.Sprintf("%s %d %s", repo.Name(), gitAge.Unix(), lastTag))
|
||||||
/*
|
/*
|
||||||
for _, tag := range repo.Tags.ListAll() {
|
for _, tag := range repo.Tags.ListAll() {
|
||||||
msg(w, fmt.Sprintf("%-60s %s", "", tag.Name()))
|
log.Info(fmt.Sprintf("%-60s %s", "", tag.Name()))
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -171,7 +167,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// log.Info("addRepo()", i, path)
|
// log.Info("addRepo()", i, path)
|
||||||
path = strings.TrimPrefix(path, me.goSrcPwd.String())
|
path = strings.TrimPrefix(path, me.goSrcPwd.String())
|
||||||
path = strings.Trim(path, "/")
|
path = strings.Trim(path, "/")
|
||||||
msg(w, fmt.Sprintf("paths:", i, path))
|
log.Info(fmt.Sprintf("paths:", i, path))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -180,11 +176,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
reponame := r.URL.Query().Get("repo")
|
reponame := r.URL.Query().Get("repo")
|
||||||
if reponame == "" {
|
if reponame == "" {
|
||||||
s := "reponame is blank " + cleanURL(r.URL.Path)
|
s := "reponame is blank " + cleanURL(r.URL.Path)
|
||||||
msg(w, s)
|
log.Info(s)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s := "reponame is " + reponame
|
s := "reponame is " + reponame
|
||||||
msg(w, s)
|
log.Info(s)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
main.go
1
main.go
|
@ -9,6 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var VERSION string
|
var VERSION string
|
||||||
|
|
||||||
//go:embed resources/*
|
//go:embed resources/*
|
||||||
var resources embed.FS
|
var resources embed.FS
|
||||||
var myargv argv
|
var myargv argv
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// attempts a simple release
|
// attempts a simple release
|
||||||
|
@ -18,22 +20,22 @@ import (
|
||||||
func simpleRelease(w http.ResponseWriter, r *http.Request) {
|
func simpleRelease(w http.ResponseWriter, r *http.Request) {
|
||||||
repoName := r.URL.Query().Get("repo")
|
repoName := r.URL.Query().Get("repo")
|
||||||
if repoName == "" {
|
if repoName == "" {
|
||||||
msg(w, "url did not have repo variable")
|
log.Info("url did not have repo variable")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// git pull (or go-clone of it doesn't exist)
|
// git pull (or go-clone of it doesn't exist)
|
||||||
repo := me.repos.View.FindRepoByName(repoName)
|
repo := me.repos.View.FindRepoByName(repoName)
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
msg(w, "repo unknown: "+repoName)
|
log.Info("repo unknown: " + repoName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
header := repo.StandardHeader()
|
header := repo.StandardHeader()
|
||||||
if repo.CheckDirty() {
|
if repo.CheckDirty() {
|
||||||
msg(w, header+"skip dirty repo")
|
log.Info(header + "skip dirty repo")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if repo.State() == "PERFECT" {
|
if repo.State() == "PERFECT" {
|
||||||
msg(w, header+"already released")
|
log.Info(header + "already released")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,15 +44,15 @@ func simpleRelease(w http.ResponseWriter, r *http.Request) {
|
||||||
if curName != mName {
|
if curName != mName {
|
||||||
// s := log.Sprintf("\trepo is not working from main branch", curName, "!=", mName)
|
// s := log.Sprintf("\trepo is not working from main branch", curName, "!=", mName)
|
||||||
s := fmt.Sprint("repo is not working from main branch ", curName, " != ", mName)
|
s := fmt.Sprint("repo is not working from main branch ", curName, " != ", mName)
|
||||||
msg(w, s)
|
log.Info(s)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd := []string{"git", "pull", "-v"}
|
cmd := []string{"git", "pull", "-v"}
|
||||||
msg(w, header+strings.Join(cmd, " "))
|
log.Info(header + strings.Join(cmd, " "))
|
||||||
if repo.Status.MergeUserToDevel() {
|
if repo.Status.MergeUserToDevel() {
|
||||||
msg(w, "THINGS SEEM OK MergeUserToDevel() returned true.")
|
log.Info("THINGS SEEM OK MergeUserToDevel() returned true.")
|
||||||
} else {
|
} else {
|
||||||
msg(w, "THINGS FAILED MergeUserToDevel() returned false")
|
log.Info("THINGS FAILED MergeUserToDevel() returned false")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue