pboling commented on code in PR #255:
URL: https://github.com/apache/skywalking-eyes/pull/255#discussion_r2636240385


##########
pkg/deps/ruby.go:
##########
@@ -136,68 +243,114 @@ 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

Review Comment:
   Fixed in 49f287d



-- 
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]

Reply via email to