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

Function parseCommentsInner

internal/tool/code_comment.go:85–140  ·  view source on GitHub ↗
(args map[string]any, defaultPath string)

Source from the content-addressed store, hash-verified

83}
84
85func parseCommentsInner(args map[string]any, defaultPath string) ([]model.LlmComment, string) {
86 var rawComments []any
87 if arr, ok := args["comments"].([]any); ok && len(arr) > 0 {
88 rawComments = arr
89 } else if s, ok := args["comments"].(string); ok && s != "" {
90 if err := json.Unmarshal([]byte(s), &rawComments); err != nil {
91 return nil, fmt.Sprintf("Error: failed to parse 'comments' JSON string: %v", err)
92 }
93 }
94 if len(rawComments) == 0 {
95 raw, _ := json.Marshal(args)
96 return nil, fmt.Sprintf("Error: 'comments' array is required. Got args: %s", string(raw))
97 }
98
99 var comments []model.LlmComment
100 for _, raw := range rawComments {
101 obj, ok := raw.(map[string]any)
102 if !ok {
103 continue
104 }
105
106 cm := model.LlmComment{}
107
108 if content, ok := obj["content"].(string); ok {
109 cm.Content = content
110 }
111 if suggestion, ok := obj["suggestion_code"].(string); ok {
112 cm.SuggestionCode = suggestion
113 }
114 if existing, ok := obj["existing_code"].(string); ok {
115 cm.ExistingCode = existing
116 }
117 if thinking, ok := obj["thinking"].(string); ok {
118 cm.Thinking = thinking
119 }
120 if category, ok := obj["category"].(string); ok {
121 cm.Category = normalizeCodeCommentCategory(category)
122 }
123 if severity, ok := obj["severity"].(string); ok {
124 cm.Severity = normalizeCodeCommentSeverity(severity)
125 }
126 if path, ok := obj["path"].(string); ok && path != "" {
127 cm.Path = path
128 }
129 if cm.Path == "" {
130 cm.Path = defaultPath
131 }
132
133 if cm.Path == "" || cm.Content == "" {
134 continue
135 }
136
137 comments = append(comments, cm)
138 }
139 return comments, ""
140}
141
142func normalizeCodeCommentCategory(category string) string {

Callers 2

ParseCommentsWithPathFunction · 0.85
ParseCommentsFunction · 0.85

Calls 2

Tested by

no test coverage detected