Feat/sp 4479 include oss file info annotation#153
Conversation
📝 WalkthroughWalkthroughAdds ChangesOSS GitHub permalink links in match comments
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 SCANOSS Code Similarity Detected📄 1 snippet matches found 🔗 View detailed findings on commit beb07d5 Files with similarities:
💡 Click the commit link above to see detailed annotations for each match. |
SCANOSS SCAN Completed 🚀
View more details on SCANOSS Action Summary |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/utils/github-comment-api.ts`:
- Around line 73-77: The prefix stripping logic at lines 76, 113, and 167
incorrectly uses indexOf('/') which finds the first slash in the string, but
this breaks for components containing slashes like 'owner/repo' or '`@scope/pkg`'.
Instead of searching for the first slash, construct the full expected prefix
pattern (combining match.component, '-', and match.ref) and search for that
complete pattern in the filePath, then extract everything after it. This ensures
the prefix is stripped correctly regardless of whether the component name
contains slashes.
- Line 275: The deduplicationKey construction uses the raw fileMatch.version
without normalization, while displayed versions are normalized elsewhere (line
147), causing semantically identical versions like v1.2.3 and 1.2.3 to generate
different dedup keys and result in duplicate comments. Apply the same version
normalization logic used on line 147 to the fileMatch.version when building the
deduplicationKey to ensure consistent deduplication across different version
formats.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 49a10ac4-9f82-4dce-9393-eaae42721888
⛔ Files ignored due to path filters (2)
dist/index.jsis excluded by!**/dist/**dist/licenses.txtis excluded by!**/dist/**
📒 Files selected for processing (4)
CHANGELOG.mdREADME.mdpackage.jsonsrc/utils/github-comment-api.ts
| // Strip the "{component}-{ref}/" prefix when present | ||
| let filePath = match.file; | ||
| if (filePath.includes('/') && match.component && filePath.startsWith(`${match.component}-`)) { | ||
| filePath = filePath.substring(filePath.indexOf('/') + 1); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Prefix stripping is incorrect for components containing /, yielding broken OSS links.
At Line 76, Line 113, and Line 167, indexOf('/') is evaluated from the beginning of the string. For components like owner/repo or @scope/pkg, this trims inside the component name instead of after "{component}-{ref}/".
Suggested fix
+function stripArchivePrefix(filePath: string, component: string): string {
+ const prefix = `${component}-`;
+ if (!component || !filePath.startsWith(prefix)) return filePath;
+ const slashAfterRef = filePath.indexOf('/', prefix.length);
+ return slashAfterRef === -1 ? filePath : filePath.substring(slashAfterRef + 1);
+}
+
function getOssFileGithubUrl(
match: { url?: string; version?: string; file: string; component: string },
lineAnchor?: string
): string | null {
if (!match.version || !match.file || !match.url) return null;
if (!match.url.startsWith('https://github.com/')) return null;
- // Strip the "{component}-{ref}/" prefix when present
- let filePath = match.file;
- if (filePath.includes('/') && match.component && filePath.startsWith(`${match.component}-`)) {
- filePath = filePath.substring(filePath.indexOf('/') + 1);
- }
+ const filePath = stripArchivePrefix(match.file, match.component);
const base = `${match.url}/blob/${match.version}/${filePath}`;
return lineAnchor ? `${base}${lineAnchor}` : base;
}
@@
- let ossRelativePath = snippet.file;
- if (ossRelativePath.includes('/') && snippet.component && ossRelativePath.startsWith(`${snippet.component}-`)) {
- ossRelativePath = ossRelativePath.substring(ossRelativePath.indexOf('/') + 1);
- }
+ const ossRelativePath = stripArchivePrefix(snippet.file, snippet.component);
@@
- const ossRelativePath =
- fileMatch.file.includes('/') && fileMatch.file.startsWith(`${fileMatch.component}-`)
- ? fileMatch.file.substring(fileMatch.file.indexOf('/') + 1)
- : fileMatch.file;
+ const ossRelativePath = stripArchivePrefix(fileMatch.file, fileMatch.component);Also applies to: 112-114, 166-168
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/utils/github-comment-api.ts` around lines 73 - 77, The prefix stripping
logic at lines 76, 113, and 167 incorrectly uses indexOf('/') which finds the
first slash in the string, but this breaks for components containing slashes
like 'owner/repo' or '`@scope/pkg`'. Instead of searching for the first slash,
construct the full expected prefix pattern (combining match.component, '-', and
match.ref) and search for that complete pattern in the filePath, then extract
everything after it. This ensures the prefix is stripped correctly regardless of
whether the component name contains slashes.
|
|
||
| // Use request deduplication to prevent duplicate comments for the same file | ||
| const deduplicationKey = `file-comment:${sha}:${filePath}:${fileMatch.component}${fileMatch.version ? `:v${fileMatch.version}` : ''}`; | ||
| const deduplicationKey = `file-comment:${sha}:${filePath}:${fileMatch.component}${fileMatch.version ? `:${fileMatch.version}` : ''}`; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Normalize version in the file-comment dedup key to avoid duplicate comments.
Line 275 uses raw fileMatch.version, but displayed versions are normalized (Line 147). v1.2.3 and 1.2.3 will be treated as different dedup keys for the same semantic version.
Suggested fix
- const deduplicationKey = `file-comment:${sha}:${filePath}:${fileMatch.component}${fileMatch.version ? `:${fileMatch.version}` : ''}`;
+ const normalizedVersion = fileMatch.version?.replace(/^v/, '');
+ const deduplicationKey = `file-comment:${sha}:${filePath}:${fileMatch.component}${normalizedVersion ? `:${normalizedVersion}` : ''}`;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/utils/github-comment-api.ts` at line 275, The deduplicationKey
construction uses the raw fileMatch.version without normalization, while
displayed versions are normalized elsewhere (line 147), causing semantically
identical versions like v1.2.3 and 1.2.3 to generate different dedup keys and
result in duplicate comments. Apply the same version normalization logic used on
line 147 to the fileMatch.version when building the deduplicationKey to ensure
consistent deduplication across different version formats.
Summary by CodeRabbit
New Features
Documentation