DEV Community

Cover image for Code Review with OneDev
Robin Shen
Robin Shen

Posted on • Updated on

Code Review with OneDev

OneDev understands importance of code review, and provides many facilities to make this process smooth and efficient. This article introduces how to perform code review in OneDev with these facilities.

Review Rule Definition

Review rule specifies who should review a certain change, and how many approvals should get to accept the change into a branch. Review rule is defined in branch protection settings like below:

Image description

In this example we define rules for changes to be accepted into main branch:

  1. The change must pass the CI build
  2. Changes touching models must get at least one approval from core team

With this rule specified, one will not be able to push changes touching models to main branch directly even with repository write permission. Instead a pull request must be submitted to go through the review process.

Reviewer Auto-Suggestion

When reviewers is specified as a group, OneDev will suggest the most appropriate members to review the change, based on commit history of touched files in the change. If for some reason, suggested reviewer can not review the change, you may simply remove and OneDev will pick up other appropriate reviewers. And you can add other reviewers as necessary even if review rule does not require it.

Image description

Pull Request Build to Verify Changes

In above screenshot, the pull request also needs to be verified by CI build. We need to disable branch protection rule temporarily to edit build spec of main branch directly to add a pull request trigger for CI job like below:

Image description

After committing change, do not forget to re-enable the branch protection setting. Check the pull request again, a CI job will be running to verify merged commit of pull request head and target branch head.

Image description

Select Changes to Review

Code review can be performed from file changes tab. File changes can be shown commit by commit, for multiple commits, or since last review (last time approve or request for changes).

Image description

Further, files can be filtered to only show interested changes. For instance, below screenshot shows all changed java files under model package:

Image description

Jump to Symbol Definition

While reviewing the change, one can jump to symbol definitions, or show all occurrences of the symbol in current commit:

Image description

Test Coverage and Code Problems

OneDev can analyze test coverage and code analysis report generated by CI job to help code review, for instance:

Image description

For an example set up of diff annotation, please check https://robinshen.medium.com/annotate-source-with-jest-eslint-information-in-onedev-c622641caa45

Code Comment to Discuss Changes

To raise concerns or suggest changes for a code snippet, just select with mouse to add a code comment:

Image description

After reviewing the changes, reviewer can give opinion by approving or requesting for changes. The pull request can only be merged after getting approvals from all reviewers.

Pull request submitter can check added code comments in code comments tab. For each suggested change, submitter can commit the change individually, or add to batch to commit together:

Image description

Free-Style Review on Commit and File

Besides pull request based review, you can open arbitrary file or commit to add comment to initiate free-style review. User changing selected code will automatically be mentioned and notified to participate in the discussion. Further, source file will be annotated with history comments to help code understanding even if file is modified or renamed.

Image description

In this mode, you can still suggest changes. When apply suggested changes, user has to tell which branch to apply the change.

That’s all. Hope these facilities helps with your next code review. Thanks for watching!

Top comments (0)