Skip to content

fix: pass credential config username to auth callbacks#2346

Merged
jcubic merged 3 commits into
isomorphic-git:mainfrom
Will-thom:will/isomorphic-git-800-credential-username
Jun 2, 2026
Merged

fix: pass credential config username to auth callbacks#2346
jcubic merged 3 commits into
isomorphic-git:mainfrom
Will-thom:will/isomorphic-git-800-credential-username

Conversation

@Will-thom

@Will-thom Will-thom commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • read credential..username from git config before invoking auth callbacks during fetch/push discovery
  • preserve explicit usernames from the URL/auth object
  • add a focused fetch test for credential config username propagation

Fixes #800

Tests

  • npx nps build.rollup
  • npx eslint src/commands/fetch.js src/commands/push.js src/utils/addCredentialUsername.js tests/test-fetch.js
  • npx prettier --check src/commands/fetch.js src/commands/push.js src/utils/addCredentialUsername.js tests/test-fetch.js
  • NODE_OPTIONS=--experimental-vm-modules --max-old-space-size-percentage=80 npx jest tests/test-fetch.js -t passes credential config username to onAuth --runInBand

Summary by CodeRabbit

  • New Features

    • Configured credential usernames for remote URLs are now automatically applied during fetch and push, reducing manual credential entry.
  • Tests

    • Added a test that confirms configured usernames are supplied to authentication handlers during fetch, including handling of authentication failures and retries.

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e09653f1-412f-41f0-8e66-85549cf84ca7

📥 Commits

Reviewing files that changed from the base of the PR and between 931c34e and b76c994.

📒 Files selected for processing (1)
  • __tests__/test-fetch.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test-fetch.js

📝 Walkthrough

Walkthrough

Adds a utility to inject per-URL credential usernames from config into auth callbacks; fetch and push now wrap their onAuth/onAuthFailure handlers with this utility. A new fetch test confirms the configured username is passed to onAuth.

Changes

Credential Username Configuration

Layer / File(s) Summary
Credential username wrapper utility
src/utils/addCredentialUsername.js
New addCredentialUsername function wraps auth callbacks to enrich auth.username from either the passed auth object or config.get(\credential.${url}.username`)`, returning falsy callbacks unchanged.
Fetch command integration and verification
src/commands/fetch.js, __tests__/test-fetch.js
Fetch imports and wraps onAuth and onAuthFailure with the utility. New test verifies that configured credential username is populated in the auth payload passed to onAuth.
Push command integration
src/commands/push.js
Push command applies the same callback wrapping pattern for onAuth and onAuthFailure in remote discovery.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the config under moonlit logs,
Found usernames hidden like tiny clogs.
I wrap the handlers, slip names inside,
So auths arrive with the right countryside.
Hop, patch, and test — now credentials glide.

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: passing credential config username to auth callbacks.
Linked Issues check ✅ Passed The PR implements the core requirement from issue #800: looking up credential..username from git config and providing it to auth callbacks during fetch/push.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the credential username feature: new utility function, integration into fetch/push commands, and a focused test.
Description check ✅ Passed The PR description clearly explains the feature, testing approach, and references the fixed issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/commands/push.js (1)

109-111: ⚡ Quick win

Add parity test coverage for push auth username injection.

Line 109 and Line 111 introduce the same callback wrapping behavior as fetch, but there’s no matching push-focused test in this PR. A targeted push test (401 flow + callback arg assertion) would lock this in and prevent regressions.

🤖 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/commands/push.js` around lines 109 - 111, The push command now wraps
onAuth and onAuthFailure with addCredentialUsername (see addCredentialUsername,
onAuth, onAuthFailure in src/commands/push.js) but there’s no corresponding test
to ensure the username gets injected during a 401 push flow; add a
unit/integration test that mirrors the existing fetch auth-tests: simulate a 401
response from the push endpoint, assert the wrapped callback receives the
injected username argument and that onAuth/onAuthFailure are called with the
augmented credentials, and include a parity test case that verifies the same
callback-arg behavior as the fetch tests to prevent regressions.
🤖 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.

Nitpick comments:
In `@src/commands/push.js`:
- Around line 109-111: The push command now wraps onAuth and onAuthFailure with
addCredentialUsername (see addCredentialUsername, onAuth, onAuthFailure in
src/commands/push.js) but there’s no corresponding test to ensure the username
gets injected during a 401 push flow; add a unit/integration test that mirrors
the existing fetch auth-tests: simulate a 401 response from the push endpoint,
assert the wrapped callback receives the injected username argument and that
onAuth/onAuthFailure are called with the augmented credentials, and include a
parity test case that verifies the same callback-arg behavior as the fetch tests
to prevent regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1ed42bcd-6ac2-471b-bc81-89c12164f630

📥 Commits

Reviewing files that changed from the base of the PR and between 955acf3 and 09fd27f.

📒 Files selected for processing (4)
  • __tests__/test-fetch.js
  • src/commands/fetch.js
  • src/commands/push.js
  • src/utils/addCredentialUsername.js

@jcubic

jcubic commented May 27, 2026

Copy link
Copy Markdown
Member

Tests failed on typechecking:

nps is executing test.typecheck : tsc -p tsconfig.json
tests/test-fetch.js(53,9): error TS2322: Type '{ request: (request: any) => Promise<{ statusCode: number; statusMessage: string; headers: {}; body: never[]; }>; }' is not assignable to type 'HttpClient'.
The types returned by 'request(...)' are incompatible between these types.
Type 'Promise<{ statusCode: number; statusMessage: string; headers: {}; body: never[]; }>' is not assignable to type 'Promise'.
Property 'url' is missing in type '{ statusCode: number; statusMessage: string; headers: {}; body: never[]; }' but required in type 'GitHttpResponse'.
The script called "test.typecheck" which runs "tsc -p tsconfig.json" failed with exit code 2 https://github.com/sezna/nps/blob/master/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
The script called "test" which runs "nps lint && nps build.test && nps test.typecheck && nps test.setup && nps test.node && nps test.chrome && nps test.teardown" failed with exit code 2 https://github.com/sezna/nps/blob/master/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code

The error came from HttpClient but the issue came from this PR.

@jcubic jcubic merged commit d9920c5 into isomorphic-git:main Jun 2, 2026
5 checks passed
@jcubic

jcubic commented Jun 2, 2026

Copy link
Copy Markdown
Member

Thanks for the fix.

@jcubic

jcubic commented Jun 2, 2026

Copy link
Copy Markdown
Member

🎉 This PR is included in version 1.38.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jcubic jcubic added the released label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

credentialManager API should also provide fill with username if stored in .git/config

2 participants