shows more versions
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
25c783fab5
commit
8c999a6993
89
main.go
89
main.go
|
@ -2,6 +2,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
|
@ -18,9 +19,13 @@ var allrepos []*repo
|
||||||
|
|
||||||
type repo struct {
|
type repo struct {
|
||||||
path string
|
path string
|
||||||
|
lasttagrev string
|
||||||
|
lasttag string
|
||||||
|
tags []string
|
||||||
|
|
||||||
pLabel *gui.Node // path label
|
pLabel *gui.Node // path label
|
||||||
bLabel *gui.Node // branch label
|
bLabel *gui.Node // branch label
|
||||||
|
lastLabel *gui.Node // last tagged version label
|
||||||
vLabel *gui.Node // version label
|
vLabel *gui.Node // version label
|
||||||
sLabel *gui.Node // git state (dirty or not?)
|
sLabel *gui.Node // git state (dirty or not?)
|
||||||
|
|
||||||
|
@ -39,19 +44,41 @@ func main() {
|
||||||
|
|
||||||
func (r *repo) scan() {
|
func (r *repo) scan() {
|
||||||
log.Info("r.path", r.path)
|
log.Info("r.path", r.path)
|
||||||
b, out := run(r.path, "git", "describe --tags")
|
out := run(r.path, "git", "describe --tags")
|
||||||
if b {
|
|
||||||
r.vLabel.SetText(out)
|
r.vLabel.SetText(out)
|
||||||
|
|
||||||
|
out = run(r.path, "git", "branch --show-current")
|
||||||
|
r.bLabel.SetText(out)
|
||||||
|
|
||||||
|
out = run(r.path, "git", "diff-index HEAD")
|
||||||
|
if out == "" {
|
||||||
|
r.sLabel.SetText("")
|
||||||
|
r.pButton.Disable()
|
||||||
|
} else {
|
||||||
|
r.sLabel.SetText("dirty")
|
||||||
|
r.pButton.Enable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out = run(r.path, "git", "rev-list --tags --max-count=1")
|
||||||
|
out = strings.TrimSpace(out)
|
||||||
|
r.lasttagrev = out
|
||||||
|
|
||||||
|
lastreal := "describe --tags " + out
|
||||||
|
// out = run(r.path, "git", "describe --tags c871d5ecf051a7dc4e3a77157cdbc0a457eb9ae1")
|
||||||
|
out = run(r.path, "git", lastreal)
|
||||||
|
r.lasttag = out
|
||||||
|
r.lastLabel.SetText(out)
|
||||||
|
|
||||||
|
r.tags = listFiles(fullpath(r.path + "/.git/refs/tags"))
|
||||||
|
|
||||||
// cmd := "dig +noall +answer www.wit.com A"
|
// cmd := "dig +noall +answer www.wit.com A"
|
||||||
// out = shell.Run(cmd)
|
// out = shell.Run(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkrepos() {
|
func checkrepos() {
|
||||||
for i, r := range allrepos {
|
for i, r := range allrepos {
|
||||||
|
log.Warn("scannning", i, r.path)
|
||||||
r.scan()
|
r.scan()
|
||||||
log.Info("scanned them all", i)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,16 +87,18 @@ func addRepo(grid *gui.Node, path string) *repo {
|
||||||
|
|
||||||
newRepo.path = path
|
newRepo.path = path
|
||||||
newRepo.pLabel = grid.NewLabel(path)
|
newRepo.pLabel = grid.NewLabel(path)
|
||||||
newRepo.vLabel = grid.NewLabel("VER")
|
newRepo.bLabel = grid.NewLabel("")
|
||||||
newRepo.bLabel = grid.NewLabel("jcarr")
|
newRepo.lastLabel = grid.NewLabel("")
|
||||||
newRepo.sLabel = grid.NewLabel("dirty")
|
newRepo.vLabel = grid.NewLabel("")
|
||||||
|
newRepo.sLabel = grid.NewLabel("")
|
||||||
|
|
||||||
newRepo.cButton = grid.NewButton("commit", func () {
|
newRepo.cButton = grid.NewButton("commit", func () {
|
||||||
log.Println("commit")
|
log.Println("commit")
|
||||||
})
|
})
|
||||||
newRepo.cButton = grid.NewButton("push", func () {
|
newRepo.pButton = grid.NewButton("push", func () {
|
||||||
log.Println("push")
|
log.Println("push")
|
||||||
})
|
})
|
||||||
|
if path == "" { return newRepo }
|
||||||
allrepos = append(allrepos, newRepo)
|
allrepos = append(allrepos, newRepo)
|
||||||
return newRepo
|
return newRepo
|
||||||
}
|
}
|
||||||
|
@ -80,23 +109,28 @@ func helloworld() {
|
||||||
|
|
||||||
box := win.Box().NewBox("bw vbox", false)
|
box := win.Box().NewBox("bw vbox", false)
|
||||||
group := box.NewGroup("test")
|
group := box.NewGroup("test")
|
||||||
grid := group.NewGrid("test", 6, 1)
|
grid := group.NewGrid("test", 7, 1)
|
||||||
|
|
||||||
grid.NewLabel("Repo")
|
grid.NewLabel("go repo")
|
||||||
|
grid.NewLabel("branch")
|
||||||
|
grid.NewLabel("last tag")
|
||||||
grid.NewLabel("Version")
|
grid.NewLabel("Version")
|
||||||
grid.NewLabel("Current branch")
|
|
||||||
grid.NewLabel("is dirty?")
|
grid.NewLabel("is dirty?")
|
||||||
grid.NewLabel("commit")
|
grid.NewLabel("commit")
|
||||||
grid.NewLabel("push to")
|
grid.NewLabel("push to")
|
||||||
|
|
||||||
newr := addRepo(grid, "go.wit.com/log")
|
addRepo(grid, "go.wit.com/log")
|
||||||
newr.scan()
|
|
||||||
addRepo(grid, "go.wit.com/arg")
|
addRepo(grid, "go.wit.com/arg")
|
||||||
addRepo(grid, "go.wit.com/spew")
|
addRepo(grid, "go.wit.com/spew")
|
||||||
addRepo(grid, "go.wit.com/shell")
|
addRepo(grid, "go.wit.com/shell")
|
||||||
addRepo(grid, "")
|
addRepo(grid, "")
|
||||||
|
addRepo(grid, "go.wit.com/gui/gui")
|
||||||
|
addRepo(grid, "go.wit.com/gui/widget")
|
||||||
|
addRepo(grid, "go.wit.com/gui/toolkits")
|
||||||
|
addRepo(grid, "go.wit.com/gui/debugger")
|
||||||
addRepo(grid, "go.wit.com/gui/gadgets")
|
addRepo(grid, "go.wit.com/gui/gadgets")
|
||||||
addRepo(grid, "go.wit.com/gui/gadgets")
|
addRepo(grid, "go.wit.com/gui/digitalocean")
|
||||||
|
addRepo(grid, "go.wit.com/gui/cloudflare")
|
||||||
|
|
||||||
box.NewButton("checkrepos()", func () {
|
box.NewButton("checkrepos()", func () {
|
||||||
checkrepos()
|
checkrepos()
|
||||||
|
@ -128,22 +162,43 @@ func smartDraw(sw *smartwindow.SmartWindow) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(path string, thing string, cmdline string) (bool, string) {
|
func fullpath(repo string) string {
|
||||||
|
return "/home/jcarr/go/src/" + repo
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(path string, thing string, cmdline string) string {
|
||||||
parts := strings.Split(cmdline, " ")
|
parts := strings.Split(cmdline, " ")
|
||||||
// Create the command
|
// Create the command
|
||||||
cmd := exec.Command(thing, parts...)
|
cmd := exec.Command(thing, parts...)
|
||||||
|
|
||||||
// Set the working directory
|
// Set the working directory
|
||||||
cmd.Dir = "/home/jcarr/go/src/" + path
|
cmd.Dir = fullpath(path)
|
||||||
|
|
||||||
// Execute the command
|
// Execute the command
|
||||||
output, err := cmd.CombinedOutput()
|
output, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err, "cmd error'd out", parts)
|
log.Error(err, "cmd error'd out", parts)
|
||||||
return false, ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the output
|
// Print the output
|
||||||
log.Info(string(output))
|
log.Info(string(output))
|
||||||
return true, string(output)
|
return string(output)
|
||||||
|
}
|
||||||
|
|
||||||
|
func listFiles(directory string) []string {
|
||||||
|
var files []string
|
||||||
|
fileInfo, err := os.ReadDir(directory)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range fileInfo {
|
||||||
|
if !file.IsDir() {
|
||||||
|
files = append(files, file.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return files
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue