fix(clone): authenticate non-GitHub forge URLs via GITLAB_TOKEN / GITEA_TOKEN (fixes #1655)#1658
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughClone handler authentication is extended from GitHub-only to multi-forge support. New resolveForgeAuth maps repository hosts (GitHub, GitLab, Gitea, Forgejo and self-hosted patterns) to environment tokens/schemes; clone URL construction and SSH normalization now use this resolver. Tests and docs updated accordingly. ChangesMulti-forge authentication support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
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 unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@packages/core/src/handlers/clone.ts`:
- Around line 63-74: resolveForgeAuth currently matches FORGE_AUTH entries
against the whole URL string; instead parse the URL's hostname (e.g., with new
URL(url).hostname.toLowerCase()) and compare the hostname to each entry's
hostPattern using exact label boundaries (hostname === entry.hostPattern ||
hostname.endsWith('.' + entry.hostPattern)) so only the correct host or its
subdomains match; handle invalid URLs by falling back to returning { token:
undefined, scheme: '' } and keep returning the matched entry's token and scheme
when found (refer to resolveForgeAuth and FORGE_AUTH to locate the fix).
🪄 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: 3ebefae8-5057-47f2-acd5-b6d9504bcb90
📒 Files selected for processing (2)
packages/core/src/handlers/clone.test.tspackages/core/src/handlers/clone.ts
|
Addressed in d2d65bd — thanks for catching the security issue! Changes:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/core/src/handlers/clone.test.ts (1)
304-309: ⚡ Quick winHarden env cleanup to keep tests order-independent.
process.envcleanup is distributed inside tests; if one test exits early, later tests can inherit stale forge tokens. Reset forge env vars inbeforeEach/afterEachfor thisdescribeblock instead of per-test deletes (Line 306-309 and per-test cleanup lines).As per coding guidelines, "**/*.{ts,tsx,test.ts}: ... keep tests deterministic with no flaky timing or network dependence without guardrails".♻️ Suggested change
describe('multi-forge authentication', () => { - afterAll(() => { + beforeEach(() => { + delete process.env.GH_TOKEN; + delete process.env.GITLAB_TOKEN; + delete process.env.GITEA_TOKEN; + }); + + afterEach(() => { + delete process.env.GH_TOKEN; delete process.env.GITLAB_TOKEN; delete process.env.GITEA_TOKEN; }); @@ - delete process.env.GITLAB_TOKEN; @@ - delete process.env.GITLAB_TOKEN; @@ - delete process.env.GITEA_TOKEN; @@ - delete process.env.GITEA_TOKEN; @@ - delete process.env.GITLAB_TOKEN;Also applies to: 311-425
🤖 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 `@packages/core/src/handlers/clone.test.ts` around lines 304 - 309, The describe block "multi-forge authentication" uses per-test env cleanup which can leave stale GITLAB_TOKEN/GITEA_TOKEN values if a test exits early; change the block to explicitly clear and restore those environment variables in beforeEach and afterEach so each test runs with a deterministic env. Locate the "describe('multi-forge authentication')" block and add a beforeEach that deletes process.env.GITLAB_TOKEN and process.env.GITEA_TOKEN (and any other forge token envs used by these tests) and an afterEach that also deletes or restores them to their original values to make tests order-independent and avoid relying on per-test deletes inside individual tests.
🤖 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 `@packages/core/src/handlers/clone.test.ts`:
- Line 430: Replace the untyped require of resolveForgeAuth inside the describe
block with a top-level typed ESM import: move the import of resolveForgeAuth out
of the test body and add an `import { resolveForgeAuth } from '...'` at the top
of the module (ensuring it uses the same module specifier as other imports),
keeping existing module mocks setup before that import so tests still mock
dependencies correctly; update any references in the describe to use the
imported resolveForgeAuth.
---
Nitpick comments:
In `@packages/core/src/handlers/clone.test.ts`:
- Around line 304-309: The describe block "multi-forge authentication" uses
per-test env cleanup which can leave stale GITLAB_TOKEN/GITEA_TOKEN values if a
test exits early; change the block to explicitly clear and restore those
environment variables in beforeEach and afterEach so each test runs with a
deterministic env. Locate the "describe('multi-forge authentication')" block and
add a beforeEach that deletes process.env.GITLAB_TOKEN and
process.env.GITEA_TOKEN (and any other forge token envs used by these tests) and
an afterEach that also deletes or restores them to their original values to make
tests order-independent and avoid relying on per-test deletes inside individual
tests.
🪄 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: fa8bdf6f-08ea-4191-ab69-167adbf62556
📒 Files selected for processing (2)
packages/core/src/handlers/clone.test.tspackages/core/src/handlers/clone.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/core/src/handlers/clone.ts
Review SummaryVerdict: minor-fixes-needed This PR extends clone authentication to support GitLab and Gitea/Forgejo in addition to GitHub. The implementation is clean and well-scoped — one genuine bug needs fixing and documentation for the new environment variables is missing before merge. Blocking issues
Suggested fixes
Minor / nice-to-have
Compliments
Reviewed via maintainer-review-pr workflow (Pi/Minimax). Aspects run: code-review, error-handling, test-coverage, comment-quality, docs-impact. |
…cleanup - Fix parsed.host → parsed.hostname to avoid port duplication in clone URLs - Generalize SSH→HTTPS conversion from GitHub-only to all forges (git@host:path) - Fix ForgeAuthEntry docstring (remove non-existent exact: true/false refs) - Add GITLAB_TOKEN/GITEA_TOKEN docs to quick-start, configuration, adapter pages - Add SSH URL + port duplication regression tests - Harden test env cleanup with beforeEach/afterEach, import afterEach from bun:test - Remove redundant per-test env cleanup (beforeEach/afterEach handles it) Addresses review by @Wirasm on coleam00#1658.
|
Thanks for the thorough review @Wirasm! All feedback addressed in 51f0c0a: Blocking fixes:
Suggested fixes:
All 58 clone tests passing. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/core/src/handlers/clone.test.ts (2)
480-510: 💤 Low valueConsider beforeEach/afterEach for env var cleanup consistency.
These unit tests set and delete env vars inline within each test, which works correctly. However, using
beforeEach/afterEach(like the multi-forge suite at lines 306-316) would improve consistency and ensure cleanup even if a test assertion fails before reaching the delete statement.♻️ Optional cleanup pattern alignment
describe('resolveForgeAuth', () => { const { resolveForgeAuth } = require('./clone'); + + beforeEach(() => { + delete process.env.GH_TOKEN; + delete process.env.GITLAB_TOKEN; + delete process.env.GITEA_TOKEN; + }); + + afterEach(() => { + delete process.env.GH_TOKEN; + delete process.env.GITLAB_TOKEN; + delete process.env.GITEA_TOKEN; + }); test('returns GH_TOKEN for github.com', () => { process.env.GH_TOKEN = 'ghp_abc'; const result = resolveForgeAuth('https://github.com/owner/repo'); expect(result).toEqual({ token: 'ghp_abc', scheme: '' }); - delete process.env.GH_TOKEN; }); test('returns GITLAB_TOKEN with oauth2: scheme for gitlab.com', () => { process.env.GITLAB_TOKEN = 'glpat-xyz'; const result = resolveForgeAuth('https://gitlab.com/owner/repo'); expect(result).toEqual({ token: 'glpat-xyz', scheme: 'oauth2:' }); - delete process.env.GITLAB_TOKEN; }); // ... similar changes for remaining tests🤖 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 `@packages/core/src/handlers/clone.test.ts` around lines 480 - 510, The tests around resolveForgeAuth currently set and delete process.env variables inline; replace those per-test inline mutations with a beforeEach that ensures relevant env vars (GH_TOKEN, GITLAB_TOKEN) are cleared or set to known defaults and an afterEach that restores the original process.env entries to guarantee cleanup on failure; update the tests that currently call process.env.GH_TOKEN / process.env.GITLAB_TOKEN and delete them to rely on the shared beforeEach/afterEach setup so each test isolates side effects and mirrors the multi-forge suite pattern.
260-262: ⚡ Quick winAlign cleanup with the new multi-forge suite pattern.
The GH_TOKEN suite sets the token in
beforeEach(line 257) but cleans up inafterAll. If a test fails or if only some tests in this suite run, the env var may leak to other tests. The new multi-forge suite (lines 312-316) demonstrates the correct pattern usingafterEachfor cleanup, ensuring determinism even when tests are interrupted.♻️ Align env var cleanup with beforeEach/afterEach pattern
- afterAll(() => { + afterEach(() => { delete process.env.GH_TOKEN; });🤖 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 `@packages/core/src/handlers/clone.test.ts` around lines 260 - 262, The GH_TOKEN test suite sets process.env.GH_TOKEN in the beforeEach block but currently removes it in afterAll, which can leak the env var; change the cleanup to an afterEach that clears process.env.GH_TOKEN to match the multi-forge suite pattern and ensure deterministic teardown even if tests fail or run partially—update the suite surrounding the beforeEach that sets GH_TOKEN to use afterEach for deletion instead of afterAll.
🤖 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 `@packages/core/src/handlers/clone.test.ts`:
- Around line 470-472: The authenticated URL rebuild in clone.ts currently omits
parsed.port so non-standard ports are stripped; update the reconstruction (where
parsed, authScheme and forgeToken are used) to append parsed.port when present
(e.g., include `:${parsed.port}` conditionally between parsed.hostname and
parsed.pathname) and then update the test in clone.test.ts that asserts the
authenticated URL (the expectation using cloneCall?.[1]?.[1]) to expect the URL
with the port preserved (e.g., include :8443).
In `@packages/core/src/handlers/clone.ts`:
- Around line 327-336: The authenticated-clone logic in
packages/core/src/handlers/clone.ts uses parsed.hostname which drops ports, so
change it to use parsed.host (hostname[:port]) when rebuilding cloneUrl inside
the forgeToken branch of the code that sets cloneUrl (refer to safeParseUrl,
workingUrl, parsed, and cloneUrl) to preserve custom ports; also add a
regression test (e.g., clone.test.ts) using a URL like
https://gitlab.example.com:8443/group/repo.git to assert the resulting
authenticated URL includes the :8443 port.
---
Nitpick comments:
In `@packages/core/src/handlers/clone.test.ts`:
- Around line 480-510: The tests around resolveForgeAuth currently set and
delete process.env variables inline; replace those per-test inline mutations
with a beforeEach that ensures relevant env vars (GH_TOKEN, GITLAB_TOKEN) are
cleared or set to known defaults and an afterEach that restores the original
process.env entries to guarantee cleanup on failure; update the tests that
currently call process.env.GH_TOKEN / process.env.GITLAB_TOKEN and delete them
to rely on the shared beforeEach/afterEach setup so each test isolates side
effects and mirrors the multi-forge suite pattern.
- Around line 260-262: The GH_TOKEN test suite sets process.env.GH_TOKEN in the
beforeEach block but currently removes it in afterAll, which can leak the env
var; change the cleanup to an afterEach that clears process.env.GH_TOKEN to
match the multi-forge suite pattern and ensure deterministic teardown even if
tests fail or run partially—update the suite surrounding the beforeEach that
sets GH_TOKEN to use afterEach for deletion instead of afterAll.
🪄 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: bb34a98d-6149-4c08-a139-fe53ca414024
📒 Files selected for processing (6)
packages/core/src/handlers/clone.test.tspackages/core/src/handlers/clone.tspackages/docs-web/src/content/docs/adapters/community/gitea.mdpackages/docs-web/src/content/docs/adapters/community/gitlab.mdpackages/docs-web/src/content/docs/getting-started/configuration.mdpackages/docs-web/src/content/docs/getting-started/quick-start.md
✅ Files skipped from review due to trivial changes (4)
- packages/docs-web/src/content/docs/adapters/community/gitlab.md
- packages/docs-web/src/content/docs/adapters/community/gitea.md
- packages/docs-web/src/content/docs/getting-started/quick-start.md
- packages/docs-web/src/content/docs/getting-started/configuration.md
| expect(cloneCall?.[1]?.[1]).toBe( | ||
| 'https://oauth2:glpat-porttest@gitlab.example.com/owner/repo' | ||
| ); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Extract the URL construction logic from clone.ts to verify port handling
rg -n -A 10 -B 5 'resolveForgeAuth|parsed\.hostname|parsed\.host' packages/core/src/handlers/clone.ts | head -60Repository: coleam00/Archon
Length of output: 1813
🏁 Script executed:
# Read the test file around lines 464-472 to see the full test context
sed -n '450,480p' packages/core/src/handlers/clone.test.tsRepository: coleam00/Archon
Length of output: 1254
🏁 Script executed:
# Check if there are other port-related tests in clone.test.ts
rg -n -B 3 -A 3 ':8443|8443|port' packages/core/src/handlers/clone.test.tsRepository: coleam00/Archon
Length of output: 2145
🏁 Script executed:
# Verify if parsed.port is available and check the full URL reconstruction logic
rg -n -B 2 -A 2 'parsed\.port' packages/core/src/handlers/clone.tsRepository: coleam00/Archon
Length of output: 41
🏁 Script executed:
# Find safeParseUrl function to see what properties are available
rg -n -A 20 'function safeParseUrl|export.*safeParseUrl' packages/core/src/handlers/clone.tsRepository: coleam00/Archon
Length of output: 792
🏁 Script executed:
# Check if there's any URL parsing utility in the codebase
fd -e ts -e tsx | xargs rg -l 'safeParseUrl' | head -10Repository: coleam00/Archon
Length of output: 95
🏁 Script executed:
# Look for any URL.parse or similar in clone.ts
rg -n 'new URL|URL\.parse|safeParseUrl' packages/core/src/handlers/clone.tsRepository: coleam00/Archon
Length of output: 227
🏁 Script executed:
# Verify URL object has port property and how it should be used
python3 << 'EOF'
# Simulate URL parsing behavior in JavaScript
from urllib.parse import urlparse
test_urls = [
'https://gitlab.example.com:8443/owner/repo',
'https://gitlab.example.com/owner/repo',
'https://oauth2:token@gitlab.example.com:8443/owner/repo',
]
for url in test_urls:
parsed = urlparse(url)
print(f"URL: {url}")
print(f" hostname: {parsed.hostname}")
print(f" port: {parsed.port}")
print(f" path: {parsed.path}")
# Show what correct reconstruction should look like
if parsed.port:
reconstructed = f"https://oauth2:token@{parsed.hostname}:{parsed.port}{parsed.path}"
else:
reconstructed = f"https://oauth2:token@{parsed.hostname}{parsed.path}"
print(f" reconstructed: {reconstructed}")
print()
EOFRepository: coleam00/Archon
Length of output: 620
🏁 Script executed:
# Check if there are other tests that verify port handling
rg -n 'port|:80|:443|:8443|:8080' packages/core/src/handlers/clone.test.ts | grep -v node_modulesRepository: coleam00/Archon
Length of output: 999
🏁 Script executed:
# Verify the implementation actually needs fixing by checking the full reconstruction logic
sed -n '320,340p' packages/core/src/handlers/clone.tsRepository: coleam00/Archon
Length of output: 869
Port is stripped from authenticated clone URL, breaking non-standard port cloning.
The implementation at line 330 of clone.ts reconstructs the URL using only parsed.hostname and parsed.pathname, completely omitting parsed.port. For git clone to connect to non-standard ports, the port must be included in the URL (e.g., https://oauth2:token@gitlab.example.com:8443/owner/repo).
The test validates this buggy behavior: with input https://gitlab.example.com:8443/owner/repo, it expects https://oauth2:glpat-porttest@gitlab.example.com/owner/repo (no port). The test comment "Should NOT contain double port" is misleading—the correct goal is to preserve a single port, not strip it entirely. This breaks cloning from self-hosted GitLab/Gitea instances on non-standard ports.
Fix required:
- Modify line 330 to conditionally include the port:
`https://${authScheme}${forgeToken}@${parsed.hostname}${parsed.port ? `:${parsed.port}` : ''}${parsed.pathname}` - Update test expectation to include the port:
'https://oauth2:glpat-porttest@gitlab.example.com:8443/owner/repo'
🤖 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 `@packages/core/src/handlers/clone.test.ts` around lines 470 - 472, The
authenticated URL rebuild in clone.ts currently omits parsed.port so
non-standard ports are stripped; update the reconstruction (where parsed,
authScheme and forgeToken are used) to append parsed.port when present (e.g.,
include `:${parsed.port}` conditionally between parsed.hostname and
parsed.pathname) and then update the test in clone.test.ts that asserts the
authenticated URL (the expectation using cloneCall?.[1]?.[1]) to expect the URL
with the port preserved (e.g., include :8443).
…cleanup - Fix parsed.host → parsed.hostname to avoid port duplication in clone URLs - Generalize SSH→HTTPS conversion from GitHub-only to all forges (git@host:path) - Fix ForgeAuthEntry docstring (remove non-existent exact: true/false refs) - Add GITLAB_TOKEN/GITEA_TOKEN docs to quick-start, configuration, adapter pages - Add SSH URL + port duplication regression tests - Harden test env cleanup with beforeEach/afterEach, import afterEach from bun:test - Remove redundant per-test env cleanup (beforeEach/afterEach handles it) Addresses review by @Wirasm on coleam00#1658.
51f0c0a to
f21784d
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/core/src/handlers/clone.ts (1)
327-336:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winCustom port on self-hosted forges is still dropped from the authenticated clone URL.
Line 330 still reads
parsed.hostname, so an input likehttps://gitlab.example.com:8443/group/repo.gitrebuilds tohttps://oauth2:<TOKEN>@gitlab.example.com/group/repo.git— the:8443is lost andgit clonewill hit the default HTTPS port. This was flagged previously and is one of the explicit PR goals (self-hosted support with custom ports). The PR notes mention a "port-duplication regression" test, but per the current code the failure mode is port omission, not duplication.Use
parsed.host(which ishostname[:port]with no duplication when the URL doesn't carry a port) and add a regression test that asserts the port survives the rewrite for a URL likehttps://gitlab.example.com:8443/group/repo.git.🔧 Proposed fix
if (forgeToken) { const parsed = safeParseUrl(workingUrl); if (parsed) { - cloneUrl = `https://${authScheme}${forgeToken}@${parsed.hostname}${parsed.pathname}`; + cloneUrl = `https://${authScheme}${forgeToken}@${parsed.host}${parsed.pathname}`; } else if (!workingUrl.startsWith('http')) { // Bare host/path form (e.g. github.com/owner/repo) cloneUrl = `https://${authScheme}${forgeToken}@${workingUrl}`; } getLog().debug('clone_authenticated'); }🤖 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 `@packages/core/src/handlers/clone.ts` around lines 327 - 336, The authenticated clone URL builder in clone.ts loses custom ports because it uses parsed.hostname; change it to use parsed.host (which includes hostname:port) when constructing cloneUrl in the block that sets cloneUrl = `https://${authScheme}${forgeToken}@${parsed.hostname}${parsed.pathname}` so it becomes `https://${authScheme}${forgeToken}@${parsed.host}${parsed.pathname}`; also add a regression test exercising the code path that parses an input like `https://gitlab.example.com:8443/group/repo.git` (using safeParseUrl/clone logic or the function that returns cloneUrl) and assert the resulting authenticated URL preserves `:8443`.
🧹 Nitpick comments (1)
packages/core/src/handlers/clone.ts (1)
54-63: ⚡ Quick winMove the
resolveForgeAuthJSDoc next to the function it documents.The docstring on lines 54-57 sits before
SELF_HOSTED_FORGE(which has its own JSDoc on line 58), so IDE tooling andtsdoc/API extractors will attach the description toSELF_HOSTED_FORGE(or drop it entirely) instead ofresolveForgeAuthon line 65. Relocate the block to immediately above the function.📝 Proposed reorder
-/** - * Resolve forge-specific authentication token and URL scheme for a repository URL. - * Returns the token and auth scheme prefix, or empty values if no token is available. - */ /** Well-known self-hosted hostname label patterns → env var + scheme. */ const SELF_HOSTED_FORGE: { label: string; envVar: string; scheme: string }[] = [ { label: 'gitlab', envVar: 'GITLAB_TOKEN', scheme: 'oauth2:' }, { label: 'gitea', envVar: 'GITEA_TOKEN', scheme: '' }, { label: 'forgejo', envVar: 'GITEA_TOKEN', scheme: '' }, ]; +/** + * Resolve forge-specific authentication token and URL scheme for a repository URL. + * Returns the token and auth scheme prefix, or empty values if no token is available. + */ export function resolveForgeAuth(url: string): { token: string | undefined; scheme: string } {🤖 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 `@packages/core/src/handlers/clone.ts` around lines 54 - 63, The JSDoc for resolveForgeAuth is currently placed above SELF_HOSTED_FORGE so tools will associate it with the wrong symbol; move the comment block currently on lines describing "Resolve forge-specific authentication token and URL scheme..." so it appears immediately above the resolveForgeAuth function declaration (reference: resolveForgeAuth) and leave the SELF_HOSTED_FORGE JSDoc with the SELF_HOSTED_FORGE constant; ensure only the resolveForgeAuth description sits directly above the resolveForgeAuth function signature so tsdoc/IDE pick it up correctly.
🤖 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.
Duplicate comments:
In `@packages/core/src/handlers/clone.ts`:
- Around line 327-336: The authenticated clone URL builder in clone.ts loses
custom ports because it uses parsed.hostname; change it to use parsed.host
(which includes hostname:port) when constructing cloneUrl in the block that sets
cloneUrl =
`https://${authScheme}${forgeToken}@${parsed.hostname}${parsed.pathname}` so it
becomes `https://${authScheme}${forgeToken}@${parsed.host}${parsed.pathname}`;
also add a regression test exercising the code path that parses an input like
`https://gitlab.example.com:8443/group/repo.git` (using safeParseUrl/clone logic
or the function that returns cloneUrl) and assert the resulting authenticated
URL preserves `:8443`.
---
Nitpick comments:
In `@packages/core/src/handlers/clone.ts`:
- Around line 54-63: The JSDoc for resolveForgeAuth is currently placed above
SELF_HOSTED_FORGE so tools will associate it with the wrong symbol; move the
comment block currently on lines describing "Resolve forge-specific
authentication token and URL scheme..." so it appears immediately above the
resolveForgeAuth function declaration (reference: resolveForgeAuth) and leave
the SELF_HOSTED_FORGE JSDoc with the SELF_HOSTED_FORGE constant; ensure only the
resolveForgeAuth description sits directly above the resolveForgeAuth function
signature so tsdoc/IDE pick it up correctly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 68c81bbe-31e9-43f0-9169-943d396b4696
📒 Files selected for processing (6)
packages/core/src/handlers/clone.test.tspackages/core/src/handlers/clone.tspackages/docs-web/src/content/docs/adapters/community/gitea.mdpackages/docs-web/src/content/docs/adapters/community/gitlab.mdpackages/docs-web/src/content/docs/getting-started/configuration.mdpackages/docs-web/src/content/docs/getting-started/quick-start.md
✅ Files skipped from review due to trivial changes (2)
- packages/docs-web/src/content/docs/adapters/community/gitlab.md
- packages/docs-web/src/content/docs/adapters/community/gitea.md
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/docs-web/src/content/docs/getting-started/configuration.md
- packages/core/src/handlers/clone.test.ts
Review SummaryVerdict: minor-fixes-needed This PR adds multi-forge clone authentication for GitLab, Gitea, and Forgejo — a solid, well-tested extension of the existing GitHub-only auth flow. The implementation is clean and follows project conventions. Two issues need attention before merge: a security concern in hostname detection and missing docs for the new env vars. Blocking issues
Suggested fixes
Minor / nice-to-have
Compliments
Reviewed via maintainer-review-pr workflow (Pi/Minimax). Aspects run: code-review, error-handling, test-coverage, comment-quality, docs-impact. |
|
Thanks for the thorough review @Wirasm! 🙏 I've pushed a follow-up commit ( Must-fix (blocking):
Should-fix: All 61 tests pass. |
…cleanup - Fix parsed.host → parsed.hostname to avoid port duplication in clone URLs - Generalize SSH→HTTPS conversion from GitHub-only to all forges (git@host:path) - Fix ForgeAuthEntry docstring (remove non-existent exact: true/false refs) - Add GITLAB_TOKEN/GITEA_TOKEN docs to quick-start, configuration, adapter pages - Add SSH URL + port duplication regression tests - Harden test env cleanup with beforeEach/afterEach, import afterEach from bun:test - Remove redundant per-test env cleanup (beforeEach/afterEach handles it) Addresses review by @Wirasm on coleam00#1658.
- Only match first hostname label for self-hosted forge detection, preventing token leakage to crafted hostnames like gitlab.example.com.gitlab.attacker.com - Remove dead gitea.com entry from FORGE_AUTH (handled by SELF_HOSTED_FORGE) - Add test for bare host/path URL form (github.com/owner/repo) - Move orphaned JSDoc comment above resolveForgeAuth function
acc36f1 to
47d88bb
Compare
…EA_TOKEN (fixes coleam00#1655) (coleam00#1658) * fix: address review feedback — hostname bug, docs, SSH support, test cleanup - Fix parsed.host → parsed.hostname to avoid port duplication in clone URLs - Generalize SSH→HTTPS conversion from GitHub-only to all forges (git@host:path) - Fix ForgeAuthEntry docstring (remove non-existent exact: true/false refs) - Add GITLAB_TOKEN/GITEA_TOKEN docs to quick-start, configuration, adapter pages - Add SSH URL + port duplication regression tests - Harden test env cleanup with beforeEach/afterEach, import afterEach from bun:test - Remove redundant per-test env cleanup (beforeEach/afterEach handles it) Addresses review by @Wirasm on coleam00#1658. * fix(clone): hostname boundary check, remove dead code, add bare URL test - Only match first hostname label for self-hosted forge detection, preventing token leakage to crafted hostnames like gitlab.example.com.gitlab.attacker.com - Remove dead gitea.com entry from FORGE_AUTH (handled by SELF_HOSTED_FORGE) - Add test for bare host/path URL form (github.com/owner/repo) - Move orphaned JSDoc comment above resolveForgeAuth function
Summary
github.comURLs — private repos on GitLab, Gitea, or Forgejo silently fail to clonegithub.com-specific string substitution with a forge-awareresolveForgeAuth()resolver that picks the right env var + URL scheme per hostnameregisterRepository(), or the chat orchestrator clone flowUX Journey
Before
After
Architecture Diagram
N/A — no new services/components. Single function addition in
clone.ts.Label Snapshot
fix,coreChange Metadata
@archon/coreLinked Issue
Closes #1655
Validation Evidence
bun test packages/core/src/handlers/clone.test.ts)bun run type-checkclean across all 10 packagesNew tests added:
resolveForgeAuth()unit tests (4)Security Impact
GH_TOKEN)sanitizeError()already covers clone failuresGITLAB_TOKENandGITEA_TOKENalready used by forge adaptersCompatibility/Migration
GH_TOKEN+github.combehavior is unchangedHuman Verification
resolveForgeAuth()mapping table matches forge adapter expectationsoauth2:prefix is correct for GitLab personal access tokensRisks and Mitigations
gitlabsubstring)github.comfirst, thengitlab.com, thengitlabSide Effects/Blast Radius
None — only the
cloneRepository()auth block is touched.Rollback Plan
Revert single commit — previous
GH_TOKEN-only logic restored.Summary by CodeRabbit
New Features
Tests
Documentation