Space Code Reviews Available From JetBrains IDEs, Space UI, or Mobile
JetBrains Space is a complete software development platform that provides project management, issue tracking, Git hosting, code reviews, continuous integration, package repositories, and remote backend orchestration for JetBrains IDEs through dev environments.
Code reviews are one of the most important tools in a programmer’s toolkit. Not only do they help to ensure that your code is high quality and bug-free, they also help keep your code readable and maintainable. In addition, code reviews can help to prevent coding errors from being introduced into your code base.
Space supports the code review process in its web interface, in your IDE, and on mobile. You and your fellow developers can create code reviews and merge requests, add single-line and multiline comments, suggest edits, and set up quality gates and safe merges to make sure that a merge commit doesn’t result in failed builds.
In this post, let’s look at your options when it comes to code reviews and merge requests in Space.
Space code reviews from JetBrains IDEs
As developers, we spend a lot of time working on code in the IDE. With Space integration, you can review code and write comments from within the IDE. Space integration is now bundled with all JetBrains IDEs: WebStorm, Rider, GoLand, CLion, and RubyMine, in addition to IntelliJ IDEA, PyCharm, and PhpStorm 2022.2.
From the welcome screen, you can browse Space projects and clone repositories, then start working on them directly. When your changes are ready, you can create a merge request and perform a code review from within the IDE.
In a code review, you can add comments and reactions and mark files as viewed/not viewed to keep track of where you are in a code review. It’s also possible to mention individual members of your team, or the entire team at once.
Curious to learn more? Head over to our previous post about working with Space code reviews in the IDE.
Code reviews and merge requests in Space
If your team is following a code review process, it probably looks something like this: As a developer, you make changes in a feature branch, then create a merge request. This merge request is reviewed by other developers on your team, who can leave comments and suggestions. You can then make changes based on the feedback, and when all reviews and automated checks have succeeded, merge the pull request into the main branch.
You’ll find an overview of your code review and its status in a panel on the right-hand side of your screen. This overview shows you everything about your code review: quality gates, potential merge conflicts, reviewers, dev environments, and linked issues.
Commits and files are both located on the panel on the left-hand side of the screen. Most of the time, you will be reviewing all commits for a merge request at once. If needed, the Changes from all commits pane lets you filter commits to work with.
For each Git repository in Space, you can configure quality gates that apply to merge request workflows. Simply put, a quality gate is a set of conditions that need to be met before you can merge your commit into a protected branch (for example, the main branch). These conditions could include a requirement to have at least two other developers verify your changes, or require one or more continuous integration jobs to run automated tests to make sure your changes don’t cause any issues. Learn more about quality gates here.
The quality gates section in a code review lets you track the number of required approvals and their statuses without any extra clicks. Automated checks can be re-run directly from your code review, and their logs are just one click away.
Finally, even with the right-hand pane collapsed, you’ll see a button that lets you merge the changes, as well as the status for each reviewer.
Comment on multiple lines in a Code Review
In a Space code review, you can add comments on multiple lines of code, making it easier to provide context for a code review. It can also help to identify potential issues that may not be apparent from looking at a single line of code.
To add a comment for several lines, open the code review or merge request, navigate to the code you’re interested in, drag your mouse pointer to select as many lines as you like, and leave your comment.
Just like single-line comments, multiple-line comments can be posted immediately or kept as drafts until the reviewer finishes their review.
Suggested edits in Merge Requests
When reviewing a merge request from your teammate, it’s sometimes easier to suggest an exact code change. You can now make quick edits to the code and post them as suggestions, instead of just leaving comments. Your colleague can easily accept (or reject) these suggestions and add them into their branch.
To suggest code changes, select a line or a fragment of code and then click Suggest changes. Space lets you edit the selected code fragment and add a comment if you’d like to explain the reasoning behind the suggested changes.
The original author can accept and commit these changes right away.
Safe Merge and Dry Run
When your team grows, your development workflows can get more complicated. Especially when many changes are merged into the main branch during the day, it gets harder to make sure none of those changes result in build or test failures.
Safe Merge creates a temporary merge commit that combines the most recent main and branch revisions, and then runs predefined automation jobs or TeamCity configurations. Only when those are successful is the merge finalized. As a result, your main branch stays in good shape!
If you want to make sure your branch is in a mergeable state, but don’t intend to finalize your merge request yet, you can use the Dry Run option. It also creates a temporary merge commit and runs your continuous integration tasks, but won’t prompt you to complete the merge.
You can enable Safe Merge and Dry Run in the settings of your repository. When setting up branch restrictions (Protected Branches | Edit “main” branch), enable the Safe Merge option. This will create a
safe-merge.json configuration file in your repository and provide a Quick Start Guide with information on how to set everything up:
Sometimes builds fail due to flaky tests or for other reasons. It may make sense to configure automatic retries, where Space will attempt to rerun failed checks and retry the Safe Merge or Dry Run without intervention.
Link Issues to Code Reviews
Why was something changed? This question can often be answered by looking at Git commit messages, but there’s more context that can be added to a change. If you link commits with a specific issue, and with related code reviews, you can always see the full history of a particular change.
Linking issues to relevant code changes also lets you and your team easily track progress on the issue and access related data.
With Space issues, you can link your commits (and merge requests), either by adding the issue ID in your commit message or code review title, or by linking them manually. Once an issue is linked, you can easily navigate from an issue to a set of commits and code reviews, and vice-versa.
Learn more about linking issues to code reviews here.
Space Code Owners
It can be hard to know who is the best person to ask for a review or approval of a merge request, especially in larger projects. The Git history may have an answer, as it will contain information about who has been working on the code.
But there’s a better way – adding a
CODEOWNERS file to your Git repository. This file outlines who owns certain paths or files in a repository, and helps you figure out who to ask for a review.
In Space, you can create a
CODEOWNERS file in the root of your repository, or in the
.space/ directory. Once added, you can set up quality gates on your repository to require a review from the relevant code owner:
The next time you make changes to a file or path that is specified in the
CODEOWNERS file, Space will automatically suggest the person or team that is required to review your changes.
If you’d like to learn more, check out this post about Space code owners.
Code Review in Mobile Apps
The Space mobile app for iOS and Android now includes a Project tab, where you can access your project issues, favorite documents, and active code reviews.
You can see code reviews, quickly review comments on your changes, and interact with the people reviewing your changes.
We’ll be adding more code review functionality to the mobile app in the future. Our goal is to ensure that the mobile app supports most of the same code review functionality that is available in the web version.
Code reviews are an essential practice for software development teams, and good code review tools can help make this process more efficient and enjoyable.
All JetBrains IDEs are bundled with Space integration, so you can work with code reviews and merge requests from within the IDE.
You can link issues to commits and code reviews to get end-to-end traceability and know exactly why certain changes made it into your software.
In Space itself, the overview pane shows you everything about your code review at a glance. Developers on your team can add code review comments and suggest code changes to the original author.
Quality gates, along with the
CODEOWNERS file and Safe Merge and Dry Run, help keep your main branch in good shape by preventing merge commits that result in failed builds.
And if you’re on iOS or Android, the Space mobile apps let you work with projects, issues, and code reviews as well.
Give JetBrains Space a try! We’d love to hear your thoughts about code review functionality in the comments.
Subscribe to Blog updates
Thanks, we've got you!