summaryrefslogtreecommitdiff
path: root/doStats.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-15 00:25:14 -0500
committerJeff Carr <[email protected]>2025-10-15 00:25:14 -0500
commitf39e5a1a15cb6f30ab6c100842e85dc73b23f4df (patch)
tree50a04fa88e5064f313faaf74e62c1bef11ac0da6 /doStats.go
parent9f83060cccb6ee50ec14c02adb6711a3700d11be (diff)
more stats
Diffstat (limited to 'doStats.go')
-rw-r--r--doStats.go53
1 files changed, 40 insertions, 13 deletions
diff --git a/doStats.go b/doStats.go
index 35b4c6d..04ad1f4 100644
--- a/doStats.go
+++ b/doStats.go
@@ -7,8 +7,11 @@ import (
"errors"
"strings"
+ "go.wit.com/lib/cobol"
+ "go.wit.com/lib/config"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
+ "google.golang.org/protobuf/types/known/timestamppb"
)
func doVerify() (string, error) {
@@ -35,19 +38,23 @@ func doStats(r *gitpb.Repo) (string, error) {
pb, err := r.LoadStats()
allerr = errors.Join(allerr, err)
+ if hasOrigin(r) {
+ log.Info("repo doesn't have origin")
+ }
+
// collect the stats
- err = collectStats(r, pb)
+ counter, err := last100(r, pb)
allerr = errors.Join(allerr, err)
+ s := log.Sprintf("found %d new hashes", counter)
+ if counter > 0 {
+ pb.Save()
+ }
// build()
- return "verify ran", nil
+ return s, nil
}
func collectStats(r *gitpb.Repo, pb *gitpb.Stats) error {
- if hasOrigin(r) {
- log.Info("repo doesn't have origin")
- }
- last100(r)
return nil
}
@@ -63,20 +70,40 @@ var standardSeperator string = "___FORGE___"
func makeFmts() string {
// fmts := strings.Fields(config.GetPanic("standardFmts"))
// fmts := strings.Fields(config.GetPanic("standardSeperator"))
- var news []string
+ var all []string
for _, fmtvar := range standardFmts {
- news = append(news, "%"+fmtvar)
+ all = append(all, "%"+fmtvar)
}
- return "--format=" + strings.Join(news, standardSeperator)
+ return "--format=" + strings.Join(all, standardSeperator)
}
-func last100(r *gitpb.Repo) error {
+func last100(r *gitpb.Repo, pb *gitpb.Stats) (int, error) {
+ var allerr error
+ var counter int
cmd := []string{"git", "log", "-n", "10", makeFmts(), "origin/" + r.GetMasterBranchName()}
- log.Info("Run:", cmd)
+ if config.If("stats") {
+ log.Info("Run:", cmd)
+ }
cmdout := r.Run(cmd)
for i, line := range cmdout.Stdout {
parts := strings.Split(line, standardSeperator)
- log.Printf("LINE:%d %v\n", i, parts)
+ hash := parts[0]
+ if config.If("stats") {
+ log.Printf("LINE:%8.8s %2d %v\n", hash, i, parts[1:])
+ }
+ found := pb.FindByHash(hash)
+ if found != nil {
+ // already have this hash
+ continue
+ }
+ counter += 1
+ astat := new(gitpb.Stat)
+ astat.Hash = hash
+ ctime, err := cobol.GetTime(parts[2])
+ allerr = errors.Join(allerr, err)
+ astat.Ctime = timestamppb.New(*ctime)
+ astat.Subject = parts[4]
+ pb.Append(astat)
}
- return nil
+ return counter, allerr
}