repolist/getPatches.go

116 lines
2.7 KiB
Go
Raw Normal View History

2024-02-19 21:11:32 -06:00
package repolist
import (
"path/filepath"
"strings"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
type Patch struct {
Ref string
giturl string
comment string
RS *repostatus.RepoStatus
}
// move all this to repolist and gowit repos
2024-02-23 09:02:51 -06:00
func (repo *RepoRow) GetPatches(oldname string, newname string) (int, []*Patch) {
2024-02-19 21:11:32 -06:00
var patchcount int
patches := make([]*Patch, 0, 0)
if oldname == newname {
return 0, nil
}
// log.Info("repo userv, develv", userv, develv)
gitcmd := []string{"git", "log", "--oneline", oldname + ".." + newname}
log.Info("Run:", gitcmd)
2024-11-08 06:43:45 -06:00
r := repo.Status.Run(gitcmd)
if r.Error != nil {
2024-12-17 06:36:28 -06:00
log.Info("git failed ", repo.GetGoPath(), "err =", r.Error)
2024-02-19 21:11:32 -06:00
return 0, nil
}
// patches = strings.Split(output, "\n")
2024-11-08 06:43:45 -06:00
log.Info("Run:", r.Stdout)
for _, line := range r.Stdout {
2024-02-19 21:11:32 -06:00
line = strings.TrimSpace(line)
if line == "" {
continue
}
parts := strings.Split(line, " ")
newp := new(Patch)
newp.RS = repo.Status
newp.Ref = parts[0]
newp.comment = strings.Join(parts[1:], " ")
log.Info("Patch line:", line, newp.RS.String())
patchcount += 1
patches = append(patches, newp)
}
return patchcount, patches
}
2024-02-23 09:02:51 -06:00
func (repo *RepoRow) GetUserPatches() (int, []*Patch) {
2024-02-19 21:11:32 -06:00
usern := repo.Status.GetUserBranchName()
develn := repo.Status.GetDevelBranchName()
userv := repo.Status.GetUserVersion()
develv := repo.Status.GetDevelVersion()
if userv == develv {
return 0, nil
}
c, all := repo.GetPatches(develn, usern)
log.Info("GetPatches() guireleaser", develn, usern, "count =", c)
return c, all
}
2024-02-23 09:02:51 -06:00
func (repo *RepoRow) GetMasterPatches() (int, []*Patch) {
2024-02-19 21:11:32 -06:00
lasttag := repo.LastTag()
mastern := repo.Status.GetMasterBranchName()
masterv := repo.Status.GetMasterVersion()
if lasttag == masterv {
return 0, nil
}
c, all := repo.GetPatches(lasttag, mastern)
log.Info("GetPatches() guireleaser", lasttag, mastern, "count =", c)
return c, all
}
2024-12-03 00:34:39 -06:00
func isEmpty(a any) bool {
return false
}
2024-02-20 14:59:18 -06:00
func (r *RepoList) MakePatchset(setdir string) bool {
for _, repo := range r.allrepos {
2024-02-19 21:11:32 -06:00
userv := repo.Status.GetUserVersion()
develv := repo.Status.GetDevelVersion()
usern := repo.Status.GetUserBranchName()
develn := repo.Status.GetDevelBranchName()
if userv == develv {
// this repo is unchanged
continue
}
2024-12-17 06:36:28 -06:00
repodir := filepath.Join(setdir, repo.GetGoPath())
2024-02-19 21:11:32 -06:00
shell.Mkdir(repodir)
// git format-patch branch1..branch2
gitcmd := []string{"git", "format-patch", "-o", repodir, develn + ".." + usern}
log.Info("Run:", gitcmd)
2024-11-08 06:43:45 -06:00
r := repo.Status.Run(gitcmd)
log.Info("output =", r.Stdout)
if r.Error == nil {
2024-12-17 06:36:28 -06:00
log.Info("patches made okay for:", repo.GetGoPath())
2024-02-19 21:11:32 -06:00
continue
}
2024-12-17 06:36:28 -06:00
log.Info("patches failed for:", repo.GetGoPath())
2024-02-19 21:11:32 -06:00
return false
}
return true
}