add patch.proto
This commit is contained in:
parent
10e1f545bb
commit
0235d4d096
5
Makefile
5
Makefile
|
@ -5,7 +5,7 @@
|
|||
# go install
|
||||
|
||||
|
||||
all: goimports forgeConfig.pb.go uuid.pb.go vet
|
||||
all: goimports forgeConfig.pb.go uuid.pb.go patch.pb.go vet
|
||||
|
||||
vet:
|
||||
@GO111MODULE=off go vet
|
||||
|
@ -30,3 +30,6 @@ forgeConfig.pb.go: forgeConfig.proto
|
|||
|
||||
uuid.pb.go: uuid.proto
|
||||
autogenpb --proto uuid.proto
|
||||
|
||||
patch.pb.go: patch.proto
|
||||
autogenpb --proto patch.proto
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
package forgepb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func (f *Forge) MakeDevelPatchSet() (*Patchs, error) {
|
||||
pset := new(Patchs)
|
||||
dir, err := os.MkdirTemp("", "forge")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer os.RemoveAll(dir) // clean up
|
||||
|
||||
loop := f.Repos.SortByGoPath()
|
||||
for loop.Scan() {
|
||||
repo := loop.Next()
|
||||
userb := repo.GetUserBranchName()
|
||||
develb := repo.GetDevelBranchName()
|
||||
|
||||
if develb == "" {
|
||||
continue
|
||||
}
|
||||
if userb == "" {
|
||||
continue
|
||||
}
|
||||
return f.makePatchSetNew(develb, userb)
|
||||
}
|
||||
return pset, nil
|
||||
}
|
||||
|
||||
func (f *Forge) makePatchSetNew(fromBranch string, toBranch string) (*Patchs, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var pset *Patchs
|
||||
|
||||
func (f *Forge) MakePatchSet() (*Patchs, error) {
|
||||
pset = new(Patchs)
|
||||
dir, err := os.MkdirTemp("", "forge")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer os.RemoveAll(dir) // clean up
|
||||
|
||||
loop := f.Repos.SortByGoPath()
|
||||
for loop.Scan() {
|
||||
repo := loop.Next()
|
||||
userb := repo.GetUserBranchName()
|
||||
develb := repo.GetDevelBranchName()
|
||||
|
||||
if develb == "" {
|
||||
continue
|
||||
}
|
||||
if userb == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
repoDir := filepath.Join(dir, repo.GoPath)
|
||||
err := os.MkdirAll(repoDir, 0755)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// git format-patch branch1..branch2
|
||||
cmd := []string{"git", "format-patch", "-o", repoDir, develb + ".." + userb}
|
||||
r := repo.Run(cmd)
|
||||
if r.Error != nil {
|
||||
log.Info("git format-patch", repo.FullPath)
|
||||
log.Info("git format-patch", cmd)
|
||||
log.Info("git format-patch error", r.Error)
|
||||
return nil, r.Error
|
||||
}
|
||||
if r.Exit != 0 {
|
||||
log.Info("git format-patch", repo.FullPath)
|
||||
log.Info("git format-patch", cmd)
|
||||
log.Info("git format-patch exit", r.Exit)
|
||||
return nil, r.Error
|
||||
}
|
||||
if len(r.Stdout) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
addPatchFiles(repoDir)
|
||||
}
|
||||
return pset, nil
|
||||
}
|
||||
|
||||
// process each file in pDir/
|
||||
func addPatchFiles(pDir string) error {
|
||||
// log.Info("ADD PATCH FILES ADDED DIR", pDir)
|
||||
var baderr error
|
||||
filepath.Walk(pDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
// Handle possible errors, like permission issues
|
||||
fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err)
|
||||
baderr = err
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
// log.Info("TESTING FILE", path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Info("addPatchFile() failed", path)
|
||||
baderr = err
|
||||
return err
|
||||
}
|
||||
patch := new(Patch)
|
||||
patch.Filename = path
|
||||
patch.Data = data
|
||||
pset.Patchs = append(pset.Patchs, patch)
|
||||
// log.Info("ADDED PATCH FILE", path)
|
||||
return nil
|
||||
})
|
||||
return baderr
|
||||
}
|
||||
|
||||
// just an example of how to walk only directories
|
||||
func onlyWalkDirs(pDir string) error {
|
||||
log.Info("DIR", pDir)
|
||||
// var all []string
|
||||
var baderr error
|
||||
filepath.WalkDir(pDir, func(path string, d os.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
// Handle possible errors, like permission issues
|
||||
fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err)
|
||||
baderr = err
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info("TESTING DIR", path)
|
||||
if d.IsDir() {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
log.Info("NEVER GETS HERE? WHAT IS THIS?", path)
|
||||
return nil
|
||||
})
|
||||
return baderr
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package forgepb
|
||||
|
||||
// functions to import and export the protobuf
|
||||
// data to and from config files
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func (f *Forge) SendPatchSet(pset *Patchs) error {
|
||||
var err error
|
||||
data, err := pset.Marshal()
|
||||
if err != nil {
|
||||
log.Info("proto.Marshal() pset(len) error", len(data), err)
|
||||
return err
|
||||
}
|
||||
now := time.Now()
|
||||
timestamp := now.Format("2006.01.02.150405") // bummer. other date doesn't work?
|
||||
cfgfile := "patchset/patchset." + timestamp + ".pb"
|
||||
log.Info("proto.Marshal() pset(len)", len(data))
|
||||
configWrite(cfgfile, data)
|
||||
|
||||
return errors.New("don't know how to send yet")
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package forgepb;
|
||||
|
||||
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||
|
||||
message Patch {
|
||||
string filename = 1; // `autogenpb:unique`
|
||||
bytes data = 2; //
|
||||
string repoPath = 3; // path to the git repo
|
||||
string branchName = 4; //
|
||||
string branchHash = 5; //
|
||||
google.protobuf.Timestamp ctime = 7; // the git commit timestamp of the version
|
||||
}
|
||||
|
||||
message Patchs { // `autogenpb:marshal`
|
||||
string uuid = 1; // `autogenpb:uuid:0703df95-6a38-4422-994b-c55d3d6001f9` // todo: add file support
|
||||
string version = 2; // could be used for protobuf schema change violations?
|
||||
repeated Patch Patchs = 3;
|
||||
string name = 4; // could be used for protobuf schema change violations?
|
||||
string comment = 5; // could be used for protobuf schema change violations?
|
||||
string gitAuthor = 6; // could be used for protobuf schema change violations?
|
||||
google.protobuf.Timestamp ctime = 7; // the git commit timestamp of the version
|
||||
}
|
Loading…
Reference in New Issue