Coder Social home page Coder Social logo

clonejo / gerritlab Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yaoyuannnn/gerritlab

0.0 1.0 0.0 83 KB

GerritLab: Gerrit-style code review for GitLab projects.

License: BSD 3-Clause "New" or "Revised" License

Shell 6.41% Python 93.59%

gerritlab's Introduction

GerritLab: Gerrit-style Code Review for GitLab Projects.

yaoyuannnn

The branch-based approach that GitLab merge request uses can slow things down when you really want to create dependent MRs so they can be reviewed in parallel. With great amount of manual effort and carefulness, you can actually achieve that by setting an MR's target branch to the one it's dependent on and making sure before merging any MRs, you change their target branch back to master (or any default main branch in your project). This becomes pretty error-prone with more than 2 MRs, not to mention that you must merge the MRs strictly following the dependency order (otherwise, branches can be accidentally deleted where outstanding MRs still have dependencies).

Does this somehow remind you of the good things about Gerrit? Yeah, in Gerrit, nothing stops you from creating dependent reviews, since every commit creates a new review. To bring this Gerrit-style code review to GitLab repos, this project implements the same git command (i.e. git review) that greatly simplifies the steps to create/update/merge MRs.

Install git-review

Clone the repo and put the local directory to your PATH. Make sure it comes before any existing git-review in PATH so when you do git review, the right executable is picked up by Git.

Install Change-Id commit-msg hook.

We need a commit-msg hook that will add a Change-Id to every commit. This Change-Id will be used as the key to find if there's an existing MR in the GitLab repo. The following installs the commit-msg hook to your project.

$ cp commit-msg path-to-your-project/.git/hooks/commit-msg

Set up a .gitreview.

Before using this tool, you need to create a .gitreview file in the root directory of your project. It needs to contain info like GitLab project ID and a private token that can be used to access the GitLab repo. Current optional configuration flags include target_branch and remove_source_branch. target_branch represents the target branch that you want the MRs to eventually merge into. By default, target_branch is master. remove_source_branch can be used to delete the source branch of an MR once it's merged. By default, this is set to True. The following shows an example of .gitreview:

[origin]
host=https://gitlab.example.com
project_id=1234
private_token=[your-private-token]
target_branch=master
remove_source_branch=True

The private_token can alternatively also be stored in your Git config:

$ git config --global gerritlab.private-token "[your-private-token]"
# OR
$ git config --local gerritlab.private-token "[your-private-token]"

Create/Update MRs.

To create/update MRs, simply do:

$ git review

This will create/update an MR for each commit on the current branch that's ahead of origin/master (if master is the target_branch). Note that if you want to create/update MRs in a remote other than the default origin, do git review my-remote. If a commit finds an existing MR with the same Change-Id in the GitLab repo, the MR will be updated with new commit. The following shows an example that creates 3 new MRs.

$ git review origin

SUCCESS

New MRs:
* https://gitlab.example.com/arch/myproject/-/merge_requests/3719 tests: Add commit a.
    master-2c77 -> master
* https://gitlab.example.com/arch/myproject/-/merge_requests/3720 tests: Add commit b.
    master-857b -> master-2c77
* https://gitlab.example.com/arch/myproject/-/merge_requests/3721 tests: Add commit c.
    master-79e5 -> master-857b
To ssh://[email protected]:12051/arch/myproject.git

Merge MRs.

For merging MRs, use the same git command with a -m or --merge flag to merge any mergeable MRs created off of the current branch, which takes into account the MR dependency chain.

$ git review -m
Merging merge requests:
* https://gitlab.example.com/myproject/-/merge_requests/110 tests: Add commit a.
    [mergeable]: True
* https://gitlab.example.com/myproject/-/merge_requests/111 tests: Add commit b.
    [mergeable]: True
* https://gitlab.example.com/myproject/-/merge_requests/109 tests: Add commit c.
    [mergeable]: True

SUCCESS

New Merged MRs:
* https://gitlab-master.example.com/myproject/-/merge_requests/110 tests: Add commit a.
    master -> master-2c77 (master)
* https://gitlab-master.example.com/myproject/-/merge_requests/111 tests: Add commit b.
    master -> master-857b (master)
* https://gitlab-master.example.com/myproject/-/merge_requests/109 tests: Add commit c.
    master -> master-79e5 (master)
To ssh://[email protected]:12051/myproject.git

Development

Run the tests

Integration tests require a submodule at unit_tests/gerritlab_tests, with a Gitlab upstream and a personal access token configured (project access tokens cannot delete MRs).

Tests can then be triggered using ./unit_tests/merge_request_test.py or just pytest.

gerritlab's People

Contributors

clonejo avatar yaoyuannnn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.