summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--repo.common.go120
-rw-r--r--repo.protofiles.go121
-rw-r--r--repo.test.go33
3 files changed, 120 insertions, 154 deletions
diff --git a/repo.common.go b/repo.common.go
index 906891a..2289eed 100644
--- a/repo.common.go
+++ b/repo.common.go
@@ -1,5 +1,14 @@
package gitpb
+import (
+ "errors"
+ "os"
+ "path/filepath"
+ "strings"
+
+ "go.wit.com/log"
+)
+
// does this repo build a binary?
func (r *Repo) IsBinary() bool {
if r.GoInfo != nil {
@@ -16,3 +25,114 @@ func (r *Repo) IsGoPlugin() bool {
}
return false
}
+
+// This returns the list of autogenerated protobuf files
+// it assumes any file *.pb.go is autogenerated
+//
+// this are made from protoc / proto-gen-go
+// these packages also use go.wit.com/apps/autogenpb
+//
+// errors() if a .proto file does not have an autogenerated .pb.go file
+func (repo *Repo) IsProtobuf() (bool, []string, error) {
+ fullp, fullc, err := scanForProtobuf(repo.FullPath)
+ protos := make(map[string]string)
+ protoc := make(map[string]string)
+ var anyfound bool = false
+ for _, s := range fullp {
+ filebase := filepath.Base(s)
+ name := strings.TrimSuffix(filebase, ".proto")
+ anyfound = true
+ protos[name] = s
+ }
+ // make sure every .proto file has a .pb.go file
+ for pname, _ := range protos {
+ var found bool = false
+ for _, s := range fullc {
+ cfilebase := filepath.Base(s)
+ cname := strings.TrimSuffix(cfilebase, ".pb.go")
+ protoc[cname] = s
+ if cname == pname {
+ found = true
+ }
+ }
+ if found {
+ // log.Info("found ok")
+ } else {
+ // log.Info("gitpb: IsProtobuf() missing compiled proto file:", pname+".pb.go")
+ err = errors.New("compiled file " + pname + ".pb.go missing")
+ }
+ }
+
+ // assume every .pb.go file is autogenerated
+ var allc []string
+ for _, testf := range fullc {
+ if strings.HasSuffix(testf, ".pb.go") {
+ basef := filepath.Base(testf)
+ allc = append(allc, basef) // no, not the 3.5" floppy disks
+ }
+ }
+ return anyfound, allc, err
+}
+
+// look for any proto files. do not enter directories
+// note: good golang libraries are best done in a single directory
+func scanForProtobuf(srcDir string) ([]string, []string, error) {
+ var protofiles []string
+ var compiled []string
+ err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ log.Log(WARN, "Error accessing path:", path, err)
+ return err
+ }
+
+ // ignore the start dir
+ if srcDir == path {
+ return nil
+ }
+
+ if strings.HasSuffix(path, ".proto") {
+ //
+ protofiles = append(protofiles, path)
+ }
+
+ if strings.HasSuffix(path, ".pb.go") {
+ compiled = append(compiled, path)
+ }
+
+ // don't go into any directories
+ if info.IsDir() {
+ return filepath.SkipDir
+ }
+ return nil
+ })
+
+ return protofiles, compiled, err
+}
+
+func (repo *Repo) GetProtoFiles() ([]string, error) {
+ var protofiles []string
+ srcDir := repo.GetFullPath()
+ err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ log.Log(WARN, "Error accessing path:", path, err)
+ return err
+ }
+
+ // ignore the start dir
+ if srcDir == path {
+ return nil
+ }
+
+ if strings.HasSuffix(path, ".proto") {
+ //
+ protofiles = append(protofiles, path)
+ }
+
+ if info.IsDir() {
+ return filepath.SkipDir
+ }
+ return nil
+ })
+
+ return protofiles, err
+}
diff --git a/repo.protofiles.go b/repo.protofiles.go
deleted file mode 100644
index 146f506..0000000
--- a/repo.protofiles.go
+++ /dev/null
@@ -1,121 +0,0 @@
-package gitpb
-
-import (
- "errors"
- "os"
- "path/filepath"
- "strings"
-
- "go.wit.com/log"
-)
-
-// This returns the list of autogenerated protobuf files
-// it assumes any file *.pb.go is autogenerated
-//
-// this are made from protoc / proto-gen-go
-// these packages also use go.wit.com/apps/autogenpb
-//
-// errors() if a .proto file does not have an autogenerated .pb.go file
-func (repo *Repo) IsProtobuf() (bool, []string, error) {
- fullp, fullc, err := scanForProtobuf(repo.FullPath)
- protos := make(map[string]string)
- protoc := make(map[string]string)
- var anyfound bool = false
- for _, s := range fullp {
- filebase := filepath.Base(s)
- name := strings.TrimSuffix(filebase, ".proto")
- anyfound = true
- protos[name] = s
- }
- // make sure every .proto file has a .pb.go file
- for pname, _ := range protos {
- var found bool = false
- for _, s := range fullc {
- cfilebase := filepath.Base(s)
- cname := strings.TrimSuffix(cfilebase, ".pb.go")
- protoc[cname] = s
- if cname == pname {
- found = true
- }
- }
- if found {
- // log.Info("found ok")
- } else {
- // log.Info("gitpb: IsProtobuf() missing compiled proto file:", pname+".pb.go")
- err = errors.New("compiled file " + pname + ".pb.go missing")
- }
- }
-
- // assume every .pb.go file is autogenerated
- var allc []string
- for _, testf := range fullc {
- if strings.HasSuffix(testf, ".pb.go") {
- basef := filepath.Base(testf)
- allc = append(allc, basef) // no, not the 3.5" floppy disks
- }
- }
- return anyfound, allc, err
-}
-
-// look for any proto files. do not enter directories
-// note: good golang libraries are best done in a single directory
-func scanForProtobuf(srcDir string) ([]string, []string, error) {
- var protofiles []string
- var compiled []string
- err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
- if err != nil {
- log.Log(WARN, "Error accessing path:", path, err)
- return err
- }
-
- // ignore the start dir
- if srcDir == path {
- return nil
- }
-
- if strings.HasSuffix(path, ".proto") {
- //
- protofiles = append(protofiles, path)
- }
-
- if strings.HasSuffix(path, ".pb.go") {
- compiled = append(compiled, path)
- }
-
- // don't go into any directories
- if info.IsDir() {
- return filepath.SkipDir
- }
- return nil
- })
-
- return protofiles, compiled, err
-}
-
-func (repo *Repo) GetProtoFiles() ([]string, error) {
- var protofiles []string
- srcDir := repo.GetFullPath()
- err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
- if err != nil {
- log.Log(WARN, "Error accessing path:", path, err)
- return err
- }
-
- // ignore the start dir
- if srcDir == path {
- return nil
- }
-
- if strings.HasSuffix(path, ".proto") {
- //
- protofiles = append(protofiles, path)
- }
-
- if info.IsDir() {
- return filepath.SkipDir
- }
- return nil
- })
-
- return protofiles, err
-}
diff --git a/repo.test.go b/repo.test.go
deleted file mode 100644
index 7fd3eb0..0000000
--- a/repo.test.go
+++ /dev/null
@@ -1,33 +0,0 @@
-// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
-// This file was autogenerated with autogenpb v0.0.62 2025-03-02_09:17:00_UTC
-// go install go.wit.com/apps/autogenpb@latest
-//
-// define which structs (messages) you want to use in the .proto file
-// Then sort.pb.go and marshal.pb.go files are autogenerated
-//
-// autogenpb uses it and has an example .proto file with instructions
-//
-
-package gitpb
-
-/*
-func (mt *ReposTable) UpdateTable(pb *Repos) {
- // mt.parent.UpdateTable(pb)
-}
-*/
-
-/*
-func (mt *ReposTable) reposCustom(w *guipb.Widget) {
- repo := mt.x.Repos[w.Location.Y-1]
- mt.CustomFunc(repo)
-}
-
-func (mt *ReposTable) Custom(f func(*Repo)) {
- mt.pb.RegisterCustom(mt.reposCustom)
- mt.CustomFunc = f
-}
-
-func (mt *ReposTable) GetUuid() string {
- return mt.pb.Uuid
-}
-*/