MCPcopy Create free account
hub / github.com/alibaba/open-code-review / ParseComments

Function ParseComments

internal/tool/code_comment.go:74–126  ·  view source on GitHub ↗

ParseComments extracts LlmComment entries from tool call arguments without writing to the Collector. Returns parsed comments and an error message (empty on success).

(args map[string]any)

Source from the content-addressed store, hash-verified

72// ParseComments extracts LlmComment entries from tool call arguments without writing
73// to the Collector. Returns parsed comments and an error message (empty on success).
74func ParseComments(args map[string]any) ([]model.LlmComment, string) {
75 var rawComments []any
76 if arr, ok := args["comments"].([]any); ok && len(arr) > 0 {
77 rawComments = arr
78 } else if s, ok := args["comments"].(string); ok && s != "" {
79 if err := json.Unmarshal([]byte(s), &rawComments); err != nil {
80 return nil, fmt.Sprintf("Error: failed to parse 'comments' JSON string: %v", err)
81 }
82 }
83 if len(rawComments) == 0 {
84 raw, _ := json.Marshal(args)
85 return nil, fmt.Sprintf("Error: 'comments' array is required. Got args: %s", string(raw))
86 }
87
88 var comments []model.LlmComment
89 for _, raw := range rawComments {
90 obj, ok := raw.(map[string]any)
91 if !ok {
92 continue
93 }
94
95 cm := model.LlmComment{}
96
97 if content, ok := obj["content"].(string); ok {
98 cm.Content = content
99 }
100 if suggestion, ok := obj["suggestion_code"].(string); ok {
101 cm.SuggestionCode = suggestion
102 }
103 if existing, ok := obj["existing_code"].(string); ok {
104 cm.ExistingCode = existing
105 }
106 if thinking, ok := obj["thinking"].(string); ok {
107 cm.Thinking = thinking
108 }
109 if category, ok := obj["category"].(string); ok {
110 cm.Category = normalizeCodeCommentCategory(category)
111 }
112 if severity, ok := obj["severity"].(string); ok {
113 cm.Severity = normalizeCodeCommentSeverity(severity)
114 }
115 if path, ok := args["path"].(string); ok {
116 cm.Path = path
117 }
118
119 if cm.Path == "" || cm.Content == "" {
120 continue
121 }
122
123 comments = append(comments, cm)
124 }
125 return comments, ""
126}
127
128func normalizeCodeCommentCategory(category string) string {
129 normalized := strings.ToLower(category)

Callers 6

executeToolCallMethod · 0.92
TestParseCommentsFunction · 0.85
TestParseComments_FieldsFunction · 0.85
ExecuteMethod · 0.85

Calls 2