Implement Gerrit SCM
What does this change
This pull request adds support for Gerrit as a version control system. It implements the core logic for creating Gerrit reviews, merging/closing them, and searching for existing changes. Future enhancements could include support for reviewers, team reviewers, assignees, draft, and label configurations.
What issue does it fix
Related to the discussion: https://github.com/lindell/multi-gitter/discussions/549
Notes for the reviewer
Changes in internal/multigitter package
As discussed above, some logic in run.go was adjusted to accommodate Gerrit's workflow:
- Before pushing a commit, the commit message is enhanced with footers such as the Gerrit
Change-Id. - To check if a feature branch exists, the
VersionControllerimplementation is queried instead of theSourceController(since Gerrit does not use branches to track changes). - With Gerrit, commits must be pushed to
refs/for/main-branchinstead ofrefs/heads/feature-branch.
To support this, the interfaces VersionControllerEnhanceCommit, VersionControllerFeatureBranchExist, and VersionControllerRemoteReference were introduced and are implemented only by the Gerrit VCS.
Changes in internal/multigitter package (Git implementations)
For both cmdgit and gogit, a new parameter was added to the Push method: remoteReference. This allows the VCS to change the remote branch name or target a namespace (see Gerrit: concept-refs-for-namespace).
Changes in internal/scm/gerrit package
Gerrit now implements all required methods from the VersionController interface, except forking, which returns an error.
CreatePullRequest and UpdatePullRequest are essentially no-ops, as in Gerrit, pushing a commit to the refs/for/<main-branch> namespace is sufficient to create or update a change.
Gerrit uses the Change-Id to determine if a commit should be associated with an existing change.
The go-gerrit library is used. GoGerritClient is a lightweight utility that simplifies the creation of mocks for testing.
Changes in cmd/platform.go
Existing flags (username, base-url, token, repo-search) are reused for authentication and search.
As with other VCS integrations, the token can also be read from the GERRIT_TOKEN environment variable.
Changes in tests package
A new TestGerritTable method was added to validate new interfaces in run.go.
With some refactoring, test cases could potentially be merged with the existing TestTable method.
Currently, the VersionController interface is used for the vcCreate, verify, and clean attributes of the test case structure (instead of using vcmock). This refactor could be addressed in a future PR, as this one is already significant.
Checklist
- [X] Made sure the PR follows the CONTRIBUTING.md guidelines
- [X] Tests if something new is added
Sorry for taking time to review this. Hope to get this reviewed pretty soon.
Thanks for a well written PR! Some minor comments.
Sorry again for the long time before review.
No worries :+1: I will have a look and come back soon
Hello :wave:
I made most of the changes and responded to the comments that are still open. If you can have a look, I will appreciate :smiley:
Thanks :pray:
Hello :wave: , Back after some vacations :palm_tree:
I updated PR to follow your last comments on the new code, added minor comments here and here, and used pagination to fetch repositories too :smiley: I think we're good to give it one last look :eyes: Thank
(PR has been rebased on master)
LGTM. One comment that I let you decide if you want to fix or not.
But please never rewrite history in an ongoing PR. It makes it much harder to compare the history. This project always squashes commits before merging, so a rebase or merge to master is the same end result but much easier to follow. (https://github.com/lindell/multi-gitter/blob/master/CONTRIBUTING.md)
Oups, sorry for that :disappointed: I’ll keep that in mind for next time.
Thanks for a well-written PR! Merging and releasing this now.
Included in release v0.58.0 🎉
Thanks, I really appreciate all your comment/feedback :+1:
Followings PR will be : supporting draft and repo parameters.