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

Function LoadComments

internal/session/comments.go:17–70  ·  view source on GitHub ↗

LoadComments replays one session's JSONL and returns every review comment recorded in it, in file-completion order. It mirrors resume replay semantics: a later checkpoint for the same fingerprint supersedes the earlier one, and a subsequent review_item_failed drops it. Comments that were persisted w

(repoDir, sessionID string)

Source from the content-addressed store, hash-verified

15// earlier one, and a subsequent review_item_failed drops it. Comments that
16// were persisted without a path inherit the record's file path.
17func LoadComments(repoDir, sessionID string) ([]model.LlmComment, error) {
18 path, err := SessionFilePath(repoDir, sessionID)
19 if err != nil {
20 return nil, err
21 }
22 type group struct {
23 comments []model.LlmComment
24 }
25 var order []*group
26 byFingerprint := map[string]*group{}
27 err = walkSessionFile(path, func(rec summaryRecord) {
28 switch rec.Type {
29 case "review_item_done", "review_item_reused":
30 var comments []model.LlmComment
31 if len(rec.Comments) > 0 {
32 if err := json.Unmarshal(rec.Comments, &comments); err != nil {
33 return
34 }
35 }
36 filePath := rec.FilePath
37 if filePath == "" {
38 filePath = rec.NewPath
39 }
40 for i := range comments {
41 if comments[i].Path == "" {
42 comments[i].Path = filePath
43 }
44 }
45 if rec.Fingerprint != "" {
46 if g, ok := byFingerprint[rec.Fingerprint]; ok {
47 g.comments = comments
48 return
49 }
50 }
51 g := &group{comments: comments}
52 order = append(order, g)
53 if rec.Fingerprint != "" {
54 byFingerprint[rec.Fingerprint] = g
55 }
56 case "review_item_failed":
57 if g, ok := byFingerprint[rec.Fingerprint]; ok {
58 g.comments = nil
59 }
60 }
61 })
62 if err != nil {
63 return nil, err
64 }
65 var out []model.LlmComment
66 for _, g := range order {
67 out = append(out, g.comments...)
68 }
69 return out, nil
70}

Calls 2

SessionFilePathFunction · 0.85
walkSessionFileFunction · 0.85