feat(gerrit): add basic authentication support (#596) #758
+153
−3
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.
Fixes:#596
This PR addresses issue #596 by adding Basic Authentication support to the Gerrit connection configuration, allowing Sourcebot to index repositories from Gerrit instances that require a username and password or HTTP token.
The approach consisted of updates across the schema, backend implementation, and testing. On the schema side, schemas/v3/gerrit.json was modified to include optional username and password fields in GerritConnectionConfig. After making this change, the schema types were regenerated by running yarn workspace @sourcebot/schemas build.
On the backend, changes were made in packages/backend/src/gerrit.ts. Both getGerritReposFromConfig and fetchAllProjects were updated to accept the new credential fields. Logic was added to construct a standard Basic Authentication header in the format Authorization: Basic base64(username:password). This header is injected into the fetch request only when both the username and password are provided, ensuring that existing behavior for public Gerrit instances remains unchanged and fully backward compatible.
For validation, a new and dedicated test suite was implemented in packages/backend/src/gerrit.test.ts to strictly verify the authentication logic. The tests confirm that the correct Authorization header is sent when both username and password are present, that no header is sent when credentials are missing, that partial credentials (such as only a username) do not trigger the header, and that credentials containing special characters (for example @ or :) are correctly Base64 encoded. All four tests passed successfully when run using the command yarn workspace @sourcebot/backend test src/gerrit.test.ts.