pboling commented on code in PR #255:
URL: https://github.com/apache/skywalking-eyes/pull/255#discussion_r2635061569
##########
pkg/deps/ruby.go:
##########
@@ -136,68 +240,111 @@ func parseGemfileLock(s string) (graph gemGraph, roots
[]string, err error) {
scanner.Split(bufio.ScanLines)
graph = make(gemGraph)
- inSpecs := false
- inDeps := false
- var current *gemSpec
+ state := &lockParserState{
+ graph: graph,
+ }
for scanner.Scan() {
- line := scanner.Text()
- if strings.HasPrefix(line, "GEM") {
- inSpecs = true
- inDeps = false
- current = nil
- continue
- }
- if strings.HasPrefix(line, "DEPENDENCIES") {
- inSpecs = false
- inDeps = true
- current = nil
- continue
- }
- if strings.TrimSpace(line) == "specs:" && inSpecs {
- // just a marker
- continue
- }
+ state.processLine(scanner.Text())
+ }
+ if err := scanner.Err(); err != nil {
+ return nil, nil, err
+ }
+ return graph, state.roots, nil
+}
- if inSpecs {
- if m := lockSpecHeader.FindStringSubmatch(line); len(m)
== 3 {
- name := m[1]
- version := m[2]
- current = &gemSpec{Name: name, Version: version}
- graph[name] = current
- continue
- }
- if current != nil {
- if m := lockDepLine.FindStringSubmatch(line);
len(m) == 2 {
- depName := m[1]
- current.Deps = append(current.Deps,
depName)
- }
- }
- continue
+type lockParserState struct {
+ inSpecs bool
+ inDeps bool
+ inPath bool
+ current *gemSpec
+ currentRemotePath string
+ graph gemGraph
+ roots []string
+}
+
+func (s *lockParserState) processLine(line string) {
+ if strings.HasPrefix(line, "GEM") {
+ s.inSpecs = true
+ s.inDeps = false
+ s.inPath = false
+ s.currentRemotePath = ""
+ s.current = nil
+ return
+ }
+ if strings.HasPrefix(line, "PATH") {
+ s.inSpecs = true
+ s.inDeps = false
+ s.inPath = true
+ s.current = nil
+ return
+ }
+ if strings.HasPrefix(line, "DEPENDENCIES") {
+ s.inSpecs = false
+ s.inDeps = true
+ s.inPath = false
+ s.current = nil
+ return
+ }
+ if strings.TrimSpace(line) == "specs:" && s.inSpecs {
+ // just a marker
+ return
+ }
+
+ if s.inSpecs {
+ s.processSpecs(line)
+ return
+ }
+
+ if s.inDeps {
+ s.processDeps(line)
+ return
+ }
+}
+
+func (s *lockParserState) processSpecs(line string) {
+ trim := strings.TrimSpace(line)
+ if strings.HasPrefix(trim, "remote:") {
+ if s.inPath {
+ s.currentRemotePath =
strings.TrimSpace(strings.TrimPrefix(trim, "remote:"))
}
Review Comment:
Fixed in 264152276eff27811baab966f382b341204f25e6
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]