59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
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(WARN, "\tmissing go.sum", rs.realPath.String())
|
|
return nil
|
|
}
|
|
defer gosum.Close()
|
|
|
|
var deps GoConfig
|
|
deps = make(GoConfig)
|
|
|
|
scanner := bufio.NewScanner(gosum)
|
|
log.Info("\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.Info("\tREPO:", rs.String(), rs.realPath.String())
|
|
log.Info("\t version mismatch:", godep, version, currentversion)
|
|
return nil
|
|
}
|
|
} else {
|
|
deps[godep] = version
|
|
log.Info("\t", godep, "=", version)
|
|
}
|
|
} else {
|
|
log.Info("\t INVALID:", parts)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
return nil
|
|
}
|
|
|
|
return deps
|
|
}
|