-
Notifications
You must be signed in to change notification settings - Fork 6
feat: enrich review comments with clickable file:line links #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DGouron
merged 3 commits into
DGouron:master
from
CreatibOfficiel:feat/clickable-links-in-review-comments
Mar 4, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * Replace file:line references in a comment body with clickable GitLab/GitHub blob links. | ||
| * | ||
| * Pattern matches references like: | ||
| * file.py:42 | ||
| * `file.py:42` | ||
| * (file.py:42) | ||
| * users/api.py:247 | ||
| * | ||
| * Produces markdown links: | ||
| * [`file.py:42`](baseUrl/project/-/blob/sha/file.py#L42) | ||
| * | ||
| * Does NOT match: | ||
| * - URLs (http://localhost:8000, https://example.com:443) | ||
| * - Bare filenames without line numbers (docker-compose.yml) | ||
| */ | ||
|
|
||
| // File path must start with a word char, contain at least one dot (extension), then :lineNumber. | ||
| // The path must NOT start with // (to exclude URLs). | ||
| const FILE_LINE_PATTERN = | ||
| /(?<prefix>[`(]?)(?<filePath>[\w][\w./-]*\.[\w]+):(?<line>\d+)(?<suffix>[`)]?)/g | ||
|
|
||
| export function enrichCommentWithLinks( | ||
| body: string, | ||
| baseUrl: string, | ||
| projectPath: string, | ||
| headSha: string, | ||
| platform: 'gitlab' | 'github' = 'gitlab', | ||
| ): string { | ||
| return body.replace(FILE_LINE_PATTERN, (match, prefix, filePath, line, suffix, offset) => { | ||
| // Skip if preceded by :// (URL pattern like https://example.com:443) | ||
| const beforeMatch = body.slice(Math.max(0, offset - 10), offset) | ||
| if (/:\/{1,2}$/.test(beforeMatch) || /:\/{1,2}[\w.-]*$/.test(beforeMatch)) { | ||
| return match | ||
| } | ||
|
|
||
| // Skip if the filePath portion doesn't look like a real file (must contain a dot for extension) | ||
| // Already handled by regex, but double check for edge cases | ||
| if (!filePath.includes('.')) { | ||
| return match | ||
| } | ||
|
|
||
CreatibOfficiel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const blobPrefix = platform === 'github' ? 'blob' : '-/blob' | ||
| const blobUrl = `${baseUrl}/${projectPath}/${blobPrefix}/${headSha}/${filePath}#L${line}` | ||
| // When wrapped in backticks, the link markdown already includes backticks — don't double them | ||
| const outerPrefix = prefix === '`' ? '' : prefix | ||
| const outerSuffix = suffix === '`' ? '' : suffix | ||
| return `${outerPrefix}[\`${filePath}:${line}\`](${blobUrl})${outerSuffix}` | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import { normalizeGitUrl } from '@/frameworks/config/configLoader.js' | ||
|
|
||
| describe('normalizeGitUrl', () => { | ||
| it('should convert SSH URL to HTTPS', () => { | ||
| expect(normalizeGitUrl('git@gitlab.com:org/repo.git')).toBe('https://gitlab.com/org/repo') | ||
| }) | ||
|
|
||
| it('should strip .git suffix from HTTPS URL', () => { | ||
| expect(normalizeGitUrl('https://gitlab.com/org/repo.git')).toBe('https://gitlab.com/org/repo') | ||
| }) | ||
|
|
||
| it('should leave HTTPS URL without .git unchanged', () => { | ||
| expect(normalizeGitUrl('https://gitlab.com/org/repo')).toBe('https://gitlab.com/org/repo') | ||
| }) | ||
|
|
||
| it('should handle SSH URL with nested groups', () => { | ||
| expect(normalizeGitUrl('git@host:group/subgroup/repo.git')).toBe('https://host/group/subgroup/repo') | ||
| }) | ||
|
|
||
| it('should pass through plain HTTPS URL without .git', () => { | ||
| expect(normalizeGitUrl('https://github.com/owner/project')).toBe('https://github.com/owner/project') | ||
| }) | ||
| }) |
32 changes: 32 additions & 0 deletions
32
src/tests/units/interface-adapters/controllers/webhook/extractBaseUrl.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import { extractBaseUrl } from '@/interface-adapters/controllers/webhook/gitlab.controller.js' | ||
|
|
||
| describe('extractBaseUrl', () => { | ||
| it('should extract protocol://host from HTTPS URL', () => { | ||
| expect(extractBaseUrl('https://gitlab.example.com/group/project.git')).toBe('https://gitlab.example.com') | ||
| }) | ||
|
|
||
| it('should extract protocol://host from HTTP URL', () => { | ||
| expect(extractBaseUrl('http://gitlab.example.com/group/project.git')).toBe('http://gitlab.example.com') | ||
| }) | ||
|
|
||
| it('should convert SSH URL to https://host', () => { | ||
| expect(extractBaseUrl('git@gitlab.example.com:group/project.git')).toBe('https://gitlab.example.com') | ||
| }) | ||
|
|
||
| it('should preserve port in HTTPS URL', () => { | ||
| expect(extractBaseUrl('https://gitlab.example.com:8443/group/project.git')).toBe('https://gitlab.example.com:8443') | ||
| }) | ||
|
|
||
| it('should extract host from SSH URL with nested groups', () => { | ||
| expect(extractBaseUrl('git@gitlab.example.com:group/subgroup/project.git')).toBe('https://gitlab.example.com') | ||
| }) | ||
|
|
||
| it('should return null for empty string', () => { | ||
| expect(extractBaseUrl('')).toBeNull() | ||
| }) | ||
|
|
||
| it('should return null for invalid URL', () => { | ||
| expect(extractBaseUrl('not-a-url')).toBeNull() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.