repostatus/deps.go

58 lines
1.2 KiB
Go
Raw Normal View History

package repostatus
import (
"bufio"
"os"
"path/filepath"
"strings"
"go.wit.com/log"
)
func (rs *RepoStatus) GetGoDeps() GoConfig {
tmp := filepath.Join(rs.realPath.String(), "go.sum")
gosum, err := os.Open(tmp)
if err != nil {
log.Log(REPO, "\tmissing go.sum", rs.realPath.String())
return nil
}
defer gosum.Close()
var deps GoConfig
deps = make(GoConfig)
scanner := bufio.NewScanner(gosum)
log.Log(REPO, "\tgosum:", tmp)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
parts := strings.Split(line, " ")
if len(parts) == 3 {
godep := strings.TrimSpace(parts[0])
version := strings.TrimSpace(parts[1])
if strings.HasSuffix(version, "/go.mod") {
version = strings.TrimSuffix(version, "/go.mod")
}
currentversion, ok := deps[godep]
if ok {
if currentversion != version {
log.Log(REPO, "\tREPO:", rs.String(), rs.realPath.String())
log.Log(REPO, "\t version mismatch:", godep, version, currentversion)
}
} else {
deps[godep] = version
log.Log(REPO, "\t", godep, "=", version)
}
} else {
log.Log(REPO, "\t INVALID:", parts)
return nil
}
}
if err := scanner.Err(); err != nil {
return nil
}
return deps
}