Skip to main content

Code Review

OneDev provides many facilities to make code review process smooth and efficient. This article introduces how to perform code review 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:

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.

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:

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.

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).

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

Jump to Symbol Definition

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

Test Coverage and Code Problems

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

For an example set up of diff annotation, please check source annotation with Jest/ESLint information

Code Comment to Discuss Changes

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

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:

After committing the change, code comments will be marked as resolved. Relevant reviewers will be notified of the new commits, and can start new round of review if necessary.

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.

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 help with your next code review. Thanks for watching!