more functionality
This commit is contained in:
@@ -7,7 +7,27 @@ import (
|
||||
"golang.org/x/mod/modfile"
|
||||
)
|
||||
|
||||
func LoadAndComputePairs(filename string) ([]libyear.Pair, error) {
|
||||
type logger interface {
|
||||
Logf(f string, s ...interface{})
|
||||
Debugf(f string, s ...interface{})
|
||||
}
|
||||
|
||||
type GoMod struct {
|
||||
IncludeIndirect bool
|
||||
ProxyLoader Queryer
|
||||
Logger logger
|
||||
}
|
||||
|
||||
func isReplaced(module string, replaces []*modfile.Replace) bool {
|
||||
for i := range replaces {
|
||||
if module == replaces[i].Old.Path {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *GoMod) LoadAndComputePairs(filename string) ([]libyear.Pair, error) {
|
||||
b, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -16,14 +36,20 @@ func LoadAndComputePairs(filename string) ([]libyear.Pair, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q := Queryer{}
|
||||
|
||||
pairs := []libyear.Pair{}
|
||||
|
||||
for v := range f.Require {
|
||||
if f.Require[v].Mod.Path != "" && f.Require[v].Mod.Version != "" {
|
||||
latest := q.GetLatestVersion(f.Require[v].Mod.Path)
|
||||
current := q.GetVersion(f.Require[v].Mod.Path, f.Require[v].Mod.Version)
|
||||
if isReplaced(f.Require[v].Mod.Path, f.Replace) {
|
||||
g.Logger.Logf("%s is replaced, skipping...\n", f.Require[v].Mod.Path)
|
||||
continue
|
||||
}
|
||||
if !g.IncludeIndirect && f.Require[v].Indirect {
|
||||
g.Logger.Logf("%s is indirect, skipping...\n", f.Require[v].Mod.Path)
|
||||
continue
|
||||
}
|
||||
latest := g.ProxyLoader.GetLatestVersion(f.Require[v].Mod.Path)
|
||||
current := g.ProxyLoader.GetVersion(f.Require[v].Mod.Path, f.Require[v].Mod.Version)
|
||||
pairs = append(pairs, libyear.Pair{
|
||||
Name: f.Require[v].Mod.Path,
|
||||
Current: current,
|
||||
|
Reference in New Issue
Block a user