guireleaser/initRepoList.go

66 lines
1.6 KiB
Go
Raw Normal View History

2024-02-18 15:09:04 -06:00
package main
// this initializes the repos
import (
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"
"go.wit.com/lib/gui/repolist"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
func (r *repoWindow) initRepoList() {
usr, _ := user.Current()
repos := parsecfg("~/.config/guireleaser")
for _, line := range repos {
log.Verbose("repo =", line)
path, mbranch, dbranch, ubranch := splitLine(line)
if mbranch == "" {
mbranch = "master"
}
if dbranch == "" {
dbranch = "devel"
}
if ubranch == "" {
ubranch = usr.Username
}
r.View.AddRepo(path, mbranch, dbranch, ubranch)
}
log.Info("scanning everything in ~/go/src")
for i, path := range repostatus.ListGitDirectories() {
// log.Info("addRepo()", i, path)
path = strings.TrimPrefix(path, me.goSrcPwd.String())
path = strings.Trim(path, "/")
log.Info("addRepo()", i, path)
r.View.AddRepo(path, "master", "devel", usr.Username)
}
}
func parsecfg(f string) []string {
homeDir, _ := os.UserHomeDir()
cfgfile := filepath.Join(homeDir, f)
content, _ := ioutil.ReadFile(cfgfile)
out := string(content)
out = strings.TrimSpace(out)
lines := strings.Split(out, "\n")
return lines
}
// returns path, master branch name, devel branch name, user branch name
func splitLine(line string) (string, string, string, string) {
var path, master, devel, user string
parts := strings.Split(line, " ")
2024-02-22 19:27:20 -06:00
path, parts = shell.RemoveFirstElement(parts)
master, parts = shell.RemoveFirstElement(parts)
devel, parts = shell.RemoveFirstElement(parts)
user, parts = shell.RemoveFirstElement(parts)
2024-02-18 15:09:04 -06:00
return path, master, devel, user
}