Skip to content

Add Gerrit forge adapter#119

Open
abhinavgautam01 wants to merge 6 commits into
git-pkgs:mainfrom
abhinavgautam01:feat/gerrit-adapter
Open

Add Gerrit forge adapter#119
abhinavgautam01 wants to merge 6 commits into
git-pkgs:mainfrom
abhinavgautam01:feat/gerrit-adapter

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Summary

Adds initial Gerrit support as a forge adapter.

This maps Gerrit projects, branches, tags, files, and changes into the existing forge interfaces where they fit cleanly. Unsupported Gerrit concepts explicitly return ErrNotSupported.

Closes #12.

What works

  • Adds gerrit forge type and detection via /config/server/version
  • Adds Gerrit REST client with XSSI prefix stripping
  • Supports repositories/projects
  • Supports branch list/create/delete
  • Supports tag listing
  • Supports file content retrieval
  • Maps Gerrit changes to pull requests for get/list/diff/comment/submit/abandon/restore
  • Supports reviewer request/removal and review submission
  • Adds explicit unsupported-service stubs for issues, labels, milestones, releases, CI, secrets, deploy keys, notifications, collaborators and commit statuses
  • Updates CLI help, config docs, README and token lookup

Tests

  • go test ./...
  • git diff --check

@mestadler

Copy link
Copy Markdown

+1 on this feature, fills the single gap that I have for the cli tool, will run a qa on it against my gerrit and provide feedback.

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this, the adapter is well structured and follows the existing gitea/gitlab shape closely. Tests pass locally and pr checkout will work for Gerrit changes for free since #117 already handles refs/-prefixed head refs.

A few things to address before merging, see inline. The main ones are the Code-Review label type, the hardcoded abandon/restore messages, and the gerrit-review.googlesource.com default which doesn't actually work with the auth scheme implemented here.

Comment thread gerrit/reviews.go Outdated
Comment thread gerrit/changes.go Outdated
Comment thread gerrit/changes.go Outdated
Comment thread gerrit/repos.go
Comment thread internal/resolve/resolve.go Outdated
Comment thread gerrit/repos.go
Comment thread gerrit/gerrit.go Outdated

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the quick turnaround. Labels, abandon/restore/submit bodies, PathUnescape and the intString cleanup all look good.

Two things from the follow-up commit:

Dropping case "gerrit" from defaultDomainForType means it now falls through to github.comresolve_test.go and repo_test.go even assert {"gerrit", "github.com"}. That's worse than the googlesource default; forge --type gerrit ... without a host will quietly hit github. Return "" for gerrit and have the callers error when the domain is empty.

The HTMLURL change in convertProject went to the wrong spot. /admin/repos/<encoded> was the correct repo page; the comment was about BlobURL building on top of it. I'd revert HTMLURL to /admin/repos/... and have BlobURL just return repoHTMLURL (no good file-browse URL without gitiles).

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

thanks for catching those,

I've reverted the HTMLURL logic back to using the /admin/repos/ endpoint and updated BlobURL to just return the repoHTMLURL . I also fixed the domain resolution so that defaultDomainForType explicitly returns an empty string for gerrit , causing the CLI to correctly error out when a domain isn't provided rather than quietly defaulting to github.com.

the test assertions have been updated to reflect this behavior too.

# Conflicts:
#	README.md
#	internal/cli/auth.go
#	internal/config/config.go

Copilot AI 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.

Pull request overview

This PR adds an initial Gerrit forge adapter to the existing multi-forge library/CLI, including auto-detection and integration into the resolver/client wiring, while explicitly returning ErrNotSupported for unsupported service surfaces.

Changes:

  • Adds gerrit as a supported ForgeType, wires it into client registration and resolver builders, and extends CLI/config help text accordingly.
  • Implements a Gerrit REST client (including XSSI prefix stripping) plus core services: repos/projects, branches, tags, files, and change→PR mappings (diff/comments/submit/abandon/restore + reviews).
  • Adds detection via GET /config/server/version and introduces stubs returning ErrNotSupported for non-mappable features.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
types.go Adds Gerrit forge type constant.
README.md Documents Gerrit support and token format.
internal/resolve/resolve.go Wires Gerrit into forge builders and adjusts domain handling.
internal/resolve/resolve_test.go Extends domain default tests for Gerrit.
internal/config/config.go Updates config type comment to include Gerrit.
internal/config/config_test.go Skips token-cmd execution tests on Windows.
internal/cli/root.go Updates CLI help text to list Gerrit.
internal/cli/repo_test.go Extends domain-from-flags tests for Gerrit.
internal/cli/auth.go Updates auth CLI help text to list Gerrit.
gerrit/gerrit.go Adds Gerrit HTTP client helpers (JSON/text, XSSI strip, auth, utilities).
gerrit/repos.go Implements repo/project get/list/create/edit and tag listing.
gerrit/branches.go Implements branch list/create/delete.
gerrit/files.go Implements file content retrieval (base64 decode).
gerrit/changes.go Implements change mapping to PRs (get/list/diff/comments/submit/abandon/restore).
gerrit/reviews.go Implements review submission + reviewer add/remove.
gerrit/url.go Implements Gerrit URL path parsing into ResourceRef.
gerrit/stubs.go Adds ErrNotSupported stubs for unsupported services.
gerrit/gerrit_test.go Adds focused unit tests for core Gerrit behaviors.
detect.go Adds Gerrit detection probe via /config/server/version.
forges_test.go Adds detection test coverage for Gerrit.
forge.go Adds Gerrit builder hook to Client.RegisterDomain and ForgeBuilders.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/resolve/resolve.go
Comment thread gerrit/changes.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gerrit adapter

4 participants