attempt custom branch names

This commit is contained in:
Jeff Carr 2025-01-05 19:45:29 -06:00
parent 7e5db53e9d
commit 6cbd7e67af
2 changed files with 124 additions and 29 deletions

View File

@ -260,3 +260,65 @@ func (fc *ForgeConfigs) FindUserBranch(thing string) string {
return match.UserBranchName
}
// allows custom devel branch names in the forge config
func (fc *ForgeConfigs) FindDevelBranch(thing string) string {
var match *ForgeConfig
all := fc.SortByGoPath() // get the list of repos
for all.Scan() {
r := all.Next()
if r.GoPath == thing {
if r.DevelBranchName != "" {
return r.DevelBranchName
}
}
base := filepath.Base(r.GoPath)
if base == thing {
if r.DevelBranchName != "" {
return r.DevelBranchName
}
}
if r.Directory {
if strings.HasPrefix(thing, r.GoPath) {
match = r
}
}
}
if match == nil {
return ""
}
return match.DevelBranchName
}
// allows custom devel branch names in the forge config
func (fc *ForgeConfigs) FindMasterBranch(thing string) string {
var match *ForgeConfig
all := fc.SortByGoPath() // get the list of repos
for all.Scan() {
r := all.Next()
if r.GoPath == thing {
if r.MasterBranchName != "" {
return r.MasterBranchName
}
}
base := filepath.Base(r.GoPath)
if base == thing {
if r.MasterBranchName != "" {
return r.MasterBranchName
}
}
if r.Directory {
if strings.HasPrefix(thing, r.GoPath) {
match = r
}
}
}
if match == nil {
return ""
}
return match.MasterBranchName
}

View File

@ -43,43 +43,76 @@ func (f *Forge) ValidGoVersion(ver string) (bool, error) {
return true, nil
}
// this is still in flux
func (f *Forge) VerifyBranchNames(repo *gitpb.Repo) {
// log.Info("init worked for", repo.GoPath)
// figure out what the name of the git master branch is
// also check the forge config
func (f *Forge) findMasterBranch(repo *gitpb.Repo) {
// check the forge config first
if bname := f.Config.FindMasterBranch(repo.GetGoPath()); bname != "" {
log.Info("FOUND CONFIG NAME", bname)
log.Info("FOUND CONFIG NAME", bname)
log.Info("FOUND CONFIG NAME", bname)
repo.SetMasterBranchName(bname)
return
}
if repo.GetMasterBranchName() == "" {
// try to guess what the 'master' branch is
if repo.IsBranch("guimaster") {
repo.SetMasterBranchName("guimaster")
} else if repo.IsBranch("master") {
if repo.IsBranch("master") {
repo.SetMasterBranchName("master")
} else if repo.IsBranch("main") {
return
}
if repo.IsBranch("main") {
repo.SetMasterBranchName("main")
} else {
// todo, figure out the name from git
return
}
// TODO: figure out the name from git
repo.SetMasterBranchName("master")
if repo.CheckoutMaster() {
} else {
cmd := []string{"git", "branch", "master"}
repo.Run(cmd)
}
}
// figure out what the name of the git devel branch is
// also check the forge config
func (f *Forge) findDevelBranch(repo *gitpb.Repo) {
// check the forge config first
if bname := f.Config.FindDevelBranch(repo.GetGoPath()); bname != "" {
repo.SetDevelBranchName(bname)
if repo.CheckoutDevel() {
} else {
cmd := []string{"git", "branch", bname}
repo.Run(cmd)
}
return
}
if repo.GetDevelBranchName() == "" {
if repo.IsBranch("guidevel") {
repo.SetDevelBranchName("guidevel")
} else if repo.IsBranch("devel") {
if repo.IsBranch("devel") {
repo.SetDevelBranchName("devel")
} else {
// forcing for now. todo: warn users
return
}
// TODO: figure out the name from git
repo.SetDevelBranchName("devel")
if repo.CheckoutDevel() {
} else {
cmd := []string{"git", "branch", "devel"}
repo.Run(cmd)
}
}
// this is still in flux
func (f *Forge) VerifyBranchNames(repo *gitpb.Repo) {
// log.Info("init worked for", repo.GoPath)
if repo.GetMasterBranchName() == "" {
f.findMasterBranch(repo)
}
if repo.GetDevelBranchName() == "" {
f.findDevelBranch(repo)
}
if repo.GetUserBranchName() == "" {