make patchset
This commit is contained in:
parent
dae2653975
commit
b7e36449de
|
@ -1,10 +1,12 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,6 +17,7 @@ func (f *Forge) MakeDevelPatchSet() (*Patchs, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir) // clean up
|
defer os.RemoveAll(dir) // clean up
|
||||||
|
pset.TmpDir = dir
|
||||||
|
|
||||||
all := f.Repos.SortByGoPath()
|
all := f.Repos.SortByGoPath()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
|
@ -28,19 +31,84 @@ func (f *Forge) MakeDevelPatchSet() (*Patchs, error) {
|
||||||
if userb == "" {
|
if userb == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return f.makePatchSetNew(develb, userb)
|
pset.StartBranchName = develb
|
||||||
|
pset.EndBranchName = userb
|
||||||
|
err := pset.makePatchSetNew(repo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return pset, nil
|
return pset, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forge) makePatchSetNew(fromBranch string, toBranch string) (*Patchs, error) {
|
func (f *Forge) MakeMasterPatchSet() (*Patchs, error) {
|
||||||
return nil, nil
|
pset := new(Patchs)
|
||||||
|
dir, err := os.MkdirTemp("", "forge")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir) // clean up
|
||||||
|
pset.TmpDir = dir
|
||||||
|
|
||||||
|
all := f.Repos.SortByGoPath()
|
||||||
|
for all.Scan() {
|
||||||
|
repo := all.Next()
|
||||||
|
startb := repo.GetMasterBranchName()
|
||||||
|
endb := repo.GetUserBranchName()
|
||||||
|
|
||||||
|
if startb == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if endb == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// log.Info("repo", repo.GoPath, startb, "..", endb)
|
||||||
|
pset.StartBranchName = startb
|
||||||
|
pset.EndBranchName = endb
|
||||||
|
err := pset.makePatchSetNew(repo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pset, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var pset *Patchs
|
func (pset *Patchs) makePatchSetNew(repo *gitpb.Repo) error {
|
||||||
|
startBranch := pset.StartBranchName
|
||||||
|
endBranch := pset.EndBranchName
|
||||||
|
repoDir := filepath.Join(pset.TmpDir, repo.GoPath)
|
||||||
|
err := os.MkdirAll(repoDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// git format-patch branch1..branch2
|
||||||
|
cmd := []string{"git", "format-patch", "-o", repoDir, startBranch + ".." + endBranch}
|
||||||
|
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 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 errors.New(fmt.Sprintf("git returned %d", r.Exit))
|
||||||
|
}
|
||||||
|
if len(r.Stdout) == 0 {
|
||||||
|
// git created no files to add
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return pset.addPatchFiles(repoDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
// var pset *Patchs
|
||||||
|
|
||||||
func (f *Forge) MakePatchSet() (*Patchs, error) {
|
func (f *Forge) MakePatchSet() (*Patchs, error) {
|
||||||
pset = new(Patchs)
|
pset := new(Patchs)
|
||||||
dir, err := os.MkdirTemp("", "forge")
|
dir, err := os.MkdirTemp("", "forge")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -85,13 +153,13 @@ func (f *Forge) MakePatchSet() (*Patchs, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
addPatchFiles(repoDir)
|
pset.addPatchFiles(repoDir)
|
||||||
}
|
}
|
||||||
return pset, nil
|
return pset, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// process each file in pDir/
|
// process each file in pDir/
|
||||||
func addPatchFiles(pDir string) error {
|
func (p *Patchs) addPatchFiles(pDir string) error {
|
||||||
// log.Info("ADD PATCH FILES ADDED DIR", pDir)
|
// log.Info("ADD PATCH FILES ADDED DIR", pDir)
|
||||||
var baderr error
|
var baderr error
|
||||||
filepath.Walk(pDir, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(pDir, func(path string, info os.FileInfo, err error) error {
|
||||||
|
@ -115,7 +183,7 @@ func addPatchFiles(pDir string) error {
|
||||||
patch := new(Patch)
|
patch := new(Patch)
|
||||||
patch.Filename = path
|
patch.Filename = path
|
||||||
patch.Data = data
|
patch.Data = data
|
||||||
pset.Patchs = append(pset.Patchs, patch)
|
p.Patchs = append(p.Patchs, patch)
|
||||||
// log.Info("ADDED PATCH FILE", path)
|
// log.Info("ADDED PATCH FILE", path)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
14
patch.proto
14
patch.proto
|
@ -17,8 +17,14 @@ message Patchs { // `autogenpb:marshal`
|
||||||
string uuid = 1; // `autogenpb:uuid:0703df95-6a38-4422-994b-c55d3d6001f9` // todo: add file support
|
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?
|
string version = 2; // could be used for protobuf schema change violations?
|
||||||
repeated Patch Patchs = 3;
|
repeated Patch Patchs = 3;
|
||||||
string name = 4; // could be used for protobuf schema change violations?
|
string name = 4; //
|
||||||
string comment = 5; // could be used for protobuf schema change violations?
|
string comment = 5; //
|
||||||
string gitAuthor = 6; // could be used for protobuf schema change violations?
|
string gitAuthorName = 6; //
|
||||||
google.protobuf.Timestamp ctime = 7; // the git commit timestamp of the version
|
string gitAuthorEmail = 7; //
|
||||||
|
google.protobuf.Timestamp ctime = 8; // create time of this patchset
|
||||||
|
string tmpDir = 9; // temp dir
|
||||||
|
string startBranchName = 10; //
|
||||||
|
string endBranchName = 11; //
|
||||||
|
string startBranchHash = 12; //
|
||||||
|
string endBranchHash = 13; //
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue