2024-11-28 00:02:27 -06:00
|
|
|
package forgepb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2024-11-28 08:35:39 -06:00
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
2024-11-28 19:56:46 -06:00
|
|
|
"go.wit.com/lib/protobuf/zoopb"
|
2024-11-28 00:02:27 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
2024-12-01 22:23:02 -06:00
|
|
|
func Init() *Forge {
|
|
|
|
f := new(Forge)
|
|
|
|
|
|
|
|
// TODO: rethink this but it works for now
|
2024-11-28 00:02:27 -06:00
|
|
|
gosrc := os.Getenv("FORGE_GOSRC")
|
2024-12-01 22:23:02 -06:00
|
|
|
if gosrc == "" {
|
2024-11-28 00:02:27 -06:00
|
|
|
// already set. ignore init()
|
2024-12-01 22:23:02 -06:00
|
|
|
goSrcDir, err := f.findGoSrc()
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("forge init() findGoSrc()", err)
|
|
|
|
}
|
|
|
|
os.Setenv("FORGE_GOSRC", goSrcDir)
|
2024-11-28 00:02:27 -06:00
|
|
|
}
|
2024-12-01 22:23:02 -06:00
|
|
|
f.goSrc = os.Getenv("FORGE_GOSRC")
|
2024-11-28 23:00:29 -06:00
|
|
|
|
|
|
|
// cache.go has Do()
|
|
|
|
// f.initOnce.Do(f.initWork)
|
|
|
|
|
2024-11-28 18:36:15 -06:00
|
|
|
f.Config = new(ForgeConfigs)
|
|
|
|
|
2024-11-28 00:02:27 -06:00
|
|
|
// load the ~/.config/forge/ config
|
|
|
|
if err := f.Config.ConfigLoad(); err != nil {
|
|
|
|
log.Warn("forgepb.ConfigLoad() failed", err)
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
2024-11-28 08:35:39 -06:00
|
|
|
|
2024-11-28 19:56:46 -06:00
|
|
|
f.Repos = new(gitpb.Repos)
|
2024-12-01 10:44:29 -06:00
|
|
|
f.Repos.ConfigLoad()
|
2024-11-28 19:56:46 -06:00
|
|
|
f.Machine = new(zoopb.Machine)
|
2024-11-28 08:35:39 -06:00
|
|
|
|
2024-11-28 21:03:51 -06:00
|
|
|
if err := f.Machine.ConfigLoad(); err != nil {
|
|
|
|
log.Warn("zoopb.ConfigLoad() failed", err)
|
|
|
|
os.Exit(-1)
|
|
|
|
}
|
|
|
|
f.Machine.InitWit()
|
|
|
|
|
2024-12-02 05:14:52 -06:00
|
|
|
log.Info("forge pre scan ", f.Repos.Len(), "repos in", f.goSrc)
|
2024-11-28 08:35:39 -06:00
|
|
|
f.ScanGoSrc()
|
2024-11-30 12:45:07 -06:00
|
|
|
log.Info("forge.Init() found", f.Repos.Len(), "repos in", f.goSrc)
|
2024-11-28 18:36:15 -06:00
|
|
|
return f
|
2024-11-28 00:02:27 -06:00
|
|
|
}
|