mirror of
https://github.com/alibaba/open-code-review.git
synced 2026-09-14 19:59:52 +08:00
533b526b4c
* 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.
63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
// SPDX-License-Identifier: Apache-2.0
|
|
// Copyright 2026 alibaba/open-code-review Contributors
|
|
|
|
// Package delegate provides the deterministic "spec" generation for delegation mode,
|
|
// where OCR produces review specifications without calling any LLM.
|
|
package delegate
|
|
|
|
import (
|
|
"github.com/alibaba/open-code-review/internal/config/rules"
|
|
)
|
|
|
|
// RuleGroup clusters files that share the same resolved rule text.
|
|
type RuleGroup struct {
|
|
ID int
|
|
Source string // "custom" | "project" | "global" | "system"
|
|
Pattern string // glob pattern that matched, or "default"
|
|
Text string // resolved rule content
|
|
Files []string
|
|
}
|
|
|
|
// GroupRules groups the given file paths by their resolved rule content.
|
|
// Files are placed in the same group only when their source, matched pattern,
|
|
// and rule text all coincide, so a group's Source/Pattern metadata is accurate
|
|
// for every file it contains. Two files with identical rule text but different
|
|
// provenance (e.g. matched by different patterns or resolved from different
|
|
// layers) stay in separate groups.
|
|
func GroupRules(resolver rules.Resolver, paths []string) []RuleGroup {
|
|
dr, hasDetail := resolver.(rules.DetailResolver)
|
|
|
|
keyIndex := make(map[string]int) // source|pattern|text -> group index
|
|
var groups []RuleGroup
|
|
|
|
for _, path := range paths {
|
|
var source, pattern, text string
|
|
if hasDetail {
|
|
detail := dr.ResolveDetail(path)
|
|
source = detail.Source
|
|
pattern = detail.Pattern
|
|
text = detail.Rule
|
|
} else {
|
|
text = resolver.Resolve(path)
|
|
source = "system"
|
|
pattern = "default"
|
|
}
|
|
|
|
key := source + "\x00" + pattern + "\x00" + text
|
|
idx, exists := keyIndex[key]
|
|
if !exists {
|
|
idx = len(groups)
|
|
keyIndex[key] = idx
|
|
groups = append(groups, RuleGroup{
|
|
ID: idx + 1,
|
|
Source: source,
|
|
Pattern: pattern,
|
|
Text: text,
|
|
})
|
|
}
|
|
groups[idx].Files = append(groups[idx].Files, path)
|
|
}
|
|
|
|
return groups
|
|
}
|