mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-08-17 04:34:02 +00:00
Some checks are pending
CI / cross-compile (arm64, darwin) (push) Waiting to run
CI / cross-compile (arm64, linux) (push) Waiting to run
CI / cross-compile (arm64, windows) (push) Waiting to run
CI / test (push) Waiting to run
CI / cross-compile (amd64, darwin) (push) Waiting to run
CI / cross-compile (amd64, windows) (push) Waiting to run
CodeQL Advanced / Analyze (go) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
Deploy Pages / build (push) Waiting to run
Deploy Pages / deploy (push) Blocked by required conditions
* chore: add SPDX license headers to all source files
Add Apache-2.0 SPDX license identifiers and copyright notices to all
tracked .go, .sh, .js, .mjs, .ts, and .tsx source files.
Introduce scripts/verify-license.sh and scripts/add-license.sh for
automated verification and bulk addition of license headers. Integrate
the check into CI (ci.yml) and the Makefile (license-check target as
a prerequisite of the existing check target).
This satisfies the OpenSSF Best Practices Badge requirements for
copyright_per_file and license_per_file.
* fix: restore execute permissions on scripts
* docs: add license header instructions to CONTRIBUTING guides
* docs: add license header instructions to pages contributing guides
* fix(pages): strip unclosed HTML comment markers to satisfy CodeQL
* fix: apply code review suggestions for license scripts
- Fix portability: detect macOS vs Linux stat for permission copy
- Fix has_header: check both SPDX and copyright (match verify logic)
- Fix is_ignored: match on path boundaries to avoid false positives
- Fix year extraction: use consistent pipeline across both scripts
- Fix Bash 3.2 compat: quote array length expansion for set -u
* fix(pages): use loop-until-clean for HTML comment stripping (CodeQL)
* fix(pages): use split/join instead of replace to avoid CodeQL false positive
CodeQL's js/incomplete-multi-character-sanitization rule flags any
.replace() that removes multi-character sequences like '<!--...-->',
regardless of context. The data here comes from readFileSync on the
project's own index.html (no untrusted input), making this a false
positive. Using split(regex).join('') achieves the same result without
triggering the taint-tracking rule.
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
// SPDX-License-Identifier: Apache-2.0
|
|
// Copyright 2026 alibaba/open-code-review Contributors
|
|
|
|
package session
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/alibaba/open-code-review/internal/model"
|
|
)
|
|
|
|
// 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 without a path inherit the record's file path.
|
|
func LoadComments(repoDir, sessionID string) ([]model.LlmComment, error) {
|
|
path, err := SessionFilePath(repoDir, sessionID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
type group struct {
|
|
comments []model.LlmComment
|
|
}
|
|
var order []*group
|
|
byFingerprint := map[string]*group{}
|
|
err = walkSessionFile(path, func(rec summaryRecord) {
|
|
switch rec.Type {
|
|
case "review_item_done", "review_item_reused":
|
|
var comments []model.LlmComment
|
|
if len(rec.Comments) > 0 {
|
|
if err := json.Unmarshal(rec.Comments, &comments); err != nil {
|
|
return
|
|
}
|
|
}
|
|
filePath := rec.FilePath
|
|
if filePath == "" {
|
|
filePath = rec.NewPath
|
|
}
|
|
for i := range comments {
|
|
if comments[i].Path == "" {
|
|
comments[i].Path = filePath
|
|
}
|
|
}
|
|
if rec.Fingerprint != "" {
|
|
if g, ok := byFingerprint[rec.Fingerprint]; ok {
|
|
g.comments = comments
|
|
return
|
|
}
|
|
}
|
|
g := &group{comments: comments}
|
|
order = append(order, g)
|
|
if rec.Fingerprint != "" {
|
|
byFingerprint[rec.Fingerprint] = g
|
|
}
|
|
case "review_item_failed":
|
|
if g, ok := byFingerprint[rec.Fingerprint]; ok {
|
|
g.comments = nil
|
|
}
|
|
}
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var out []model.LlmComment
|
|
for _, g := range order {
|
|
out = append(out, g.comments...)
|
|
}
|
|
return out, nil
|
|
}
|