patch handling now at forge.wit.com
This commit is contained in:
parent
40689e8761
commit
b09306940e
6
Makefile
6
Makefile
|
@ -25,6 +25,12 @@ install:
|
||||||
GO111MODULE=off go install \
|
GO111MODULE=off go install \
|
||||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||||
|
|
||||||
|
prod: build
|
||||||
|
make stop
|
||||||
|
cp gowebd /usr/bin/gowebd
|
||||||
|
make start
|
||||||
|
make log
|
||||||
|
|
||||||
log:
|
log:
|
||||||
@#systemctl status gowebd.service
|
@#systemctl status gowebd.service
|
||||||
journalctl -f -xeu gowebd.service
|
journalctl -f -xeu gowebd.service
|
||||||
|
|
166
doPatchsets.go
166
doPatchsets.go
|
@ -1,166 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"go.wit.com/lib/gui/shell"
|
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
|
||||||
"go.wit.com/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func doSendPatchsets(w http.ResponseWriter) {
|
|
||||||
// log.HttpMode(w)
|
|
||||||
// defer log.HttpMode(nil)
|
|
||||||
|
|
||||||
dirname := filepath.Join(LIBDIR, "patchset/")
|
|
||||||
// Open the directory
|
|
||||||
entries, err := os.ReadDir(dirname)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error reading directory: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var psets *forgepb.Patchsets
|
|
||||||
psets = forgepb.NewPatchsets() // this sets the proper handshake protobuf UUID
|
|
||||||
|
|
||||||
// Iterate through the directory entries
|
|
||||||
for _, entry := range entries {
|
|
||||||
// Check if the entry is a file and matches the *.pb pattern
|
|
||||||
if !entry.IsDir() && filepath.Ext(entry.Name()) == ".pb" {
|
|
||||||
bytes, err := os.ReadFile(filepath.Join(dirname, entry.Name()))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(w, entry.Name(), err)
|
|
||||||
fmt.Println(entry.Name(), err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var p *forgepb.Patchset
|
|
||||||
p = new(forgepb.Patchset)
|
|
||||||
err = p.Unmarshal(bytes)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(w, entry.Name(), err)
|
|
||||||
fmt.Println(entry.Name(), err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
psets.Append(p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// marshal the protobuf to xfer over the socket
|
|
||||||
data, err := psets.Marshal()
|
|
||||||
if err != nil {
|
|
||||||
log.Info("patchsets.Marshal() to wire failed", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
start := time.Now()
|
|
||||||
log.Info("going to w.Write(data) with len", len(data))
|
|
||||||
w.Write(data)
|
|
||||||
age := shell.FormatDuration(time.Since(start))
|
|
||||||
log.Printf("Done with xfer in (%s). happy hacking!\n", age)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPatchset(w http.ResponseWriter, pbname string) {
|
|
||||||
if pbname == "" {
|
|
||||||
fmt.Fprintf(w, "filename was empty")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
msg := fmt.Sprintf("filename = %s\n", pbname)
|
|
||||||
log.Info(msg)
|
|
||||||
|
|
||||||
filename := filepath.Join(LIBDIR, "patchset/", pbname)
|
|
||||||
data, err := os.ReadFile(filename)
|
|
||||||
if err != nil {
|
|
||||||
msg := fmt.Sprintf("Error reading file %s: %v\n", filename, err)
|
|
||||||
fmt.Printf(msg)
|
|
||||||
fmt.Fprintf(w, msg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var m *forgepb.Patchset
|
|
||||||
m = new(forgepb.Patchset)
|
|
||||||
if err := m.Unmarshal(data); err != nil {
|
|
||||||
msg := fmt.Sprintf("proto.Unmarshal() failed on %s len=%d\n", filename, len(data))
|
|
||||||
fmt.Printf(msg)
|
|
||||||
fmt.Fprintf(w, msg)
|
|
||||||
msg = fmt.Sprintf("proto.Unmarshal() error %v\n", err)
|
|
||||||
fmt.Printf(msg)
|
|
||||||
fmt.Fprintf(w, msg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Info("going to w.Write(data) with len", len(data))
|
|
||||||
w.Write(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func listPatchsets(w http.ResponseWriter) {
|
|
||||||
dirname := filepath.Join(LIBDIR, "patchset/")
|
|
||||||
// Open the directory
|
|
||||||
entries, err := os.ReadDir(dirname)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error reading directory: %v\n", err)
|
|
||||||
fmt.Fprintf(w, "Error reading directory: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate through the directory entries
|
|
||||||
for _, entry := range entries {
|
|
||||||
// Check if the entry is a file and matches the *.pb pattern
|
|
||||||
if !entry.IsDir() && filepath.Ext(entry.Name()) == ".pb" {
|
|
||||||
bytes, err := os.ReadFile(filepath.Join(dirname, entry.Name()))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(w, entry.Name(), err)
|
|
||||||
fmt.Println(entry.Name(), err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
var p *forgepb.Patchset
|
|
||||||
p = new(forgepb.Patchset)
|
|
||||||
err = p.Unmarshal(bytes)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(w, entry.Name(), err)
|
|
||||||
fmt.Println(entry.Name(), err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
author := "Author: " + p.GitAuthorName
|
|
||||||
author += " <" + p.GitAuthorEmail + ">"
|
|
||||||
|
|
||||||
// author := "Author: " + os.Getenv("GIT_AUTHOR_NAME")
|
|
||||||
// author += " <" + os.Getenv("GIT_AUTHOR_EMAIL") + ">"
|
|
||||||
fmt.Fprintln(w, entry.Name(), p.Name, p.Comment, author)
|
|
||||||
fmt.Println(entry.Name(), p.Name, p.Comment, author)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func savePatchset(w http.ResponseWriter, msg []byte) {
|
|
||||||
log.Info("proto.Unmarshal() try message len", len(msg))
|
|
||||||
var m *forgepb.Patchset
|
|
||||||
m = new(forgepb.Patchset)
|
|
||||||
if err := m.Unmarshal(msg); err != nil {
|
|
||||||
log.Info("proto.Unmarshal() failed on wire message len", len(msg))
|
|
||||||
log.Info("error =", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Info("GOT patchset:", len(msg))
|
|
||||||
fmt.Fprintln(w, "GOT patchset:", len(msg))
|
|
||||||
all := m.Patches.SortByFilename()
|
|
||||||
for all.Scan() {
|
|
||||||
repo := all.Next()
|
|
||||||
log.Info("filename:", repo.Filename)
|
|
||||||
fmt.Fprintln(w, "filename:", repo.Filename)
|
|
||||||
}
|
|
||||||
now := time.Now()
|
|
||||||
// timestamp := now.Format("2022.07.18.190545") // 50yr shout out to K&R
|
|
||||||
timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work?
|
|
||||||
filename := filepath.Join(LIBDIR, "patchset/", timestamp+".submitted.pb")
|
|
||||||
regfile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
|
||||||
if err != nil {
|
|
||||||
log.Info("filename open error:", filename, err)
|
|
||||||
fmt.Fprintln(w, "filename open error:", filename, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
regfile.Write(msg)
|
|
||||||
regfile.Close()
|
|
||||||
}
|
|
19
http.go
19
http.go
|
@ -78,25 +78,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/patchset" {
|
|
||||||
savePatchset(w, msg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if route == "/GetPatchsets" {
|
|
||||||
doSendPatchsets(w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if route == "/patchsetlist" {
|
|
||||||
listPatchsets(w)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if route == "/patchsetget" {
|
|
||||||
filename := r.URL.Query().Get("filename")
|
|
||||||
getPatchset(w, filename)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if route == "/goReference.svg" {
|
if route == "/goReference.svg" {
|
||||||
writeFile(w, "goReference.svg")
|
writeFile(w, "goReference.svg")
|
||||||
return
|
return
|
||||||
|
|
|
@ -27,7 +27,7 @@ func repoHTML(w http.ResponseWriter, gourl string, realurl string) {
|
||||||
fmt.Fprintln(w, "<meta http-equiv=\"refresh\" content=\"0; url="+realurl+"\">")
|
fmt.Fprintln(w, "<meta http-equiv=\"refresh\" content=\"0; url="+realurl+"\">")
|
||||||
fmt.Fprintln(w, "</head>")
|
fmt.Fprintln(w, "</head>")
|
||||||
fmt.Fprintln(w, "<body>")
|
fmt.Fprintln(w, "<body>")
|
||||||
fmt.Fprintln(w, "Nothing to see here. Please <a href=\""+realurl+"\">move along</a>.\"")
|
fmt.Fprintln(w, "Redirecting to git repo url. Please <a href=\""+realurl+"\">move along</a>.\"")
|
||||||
fmt.Fprintln(w, "</body>")
|
fmt.Fprintln(w, "</body>")
|
||||||
fmt.Fprintln(w, "</html>")
|
fmt.Fprintln(w, "</html>")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue