crux
crux
The CRUX dashboard is integrated within Code Browser and provides a way to
publish, view, and respond to code reviews (CRs).
The CRUX CLI allows you to create and update code reviews from the command-line.
If you are on a Cloud Desktop, you can skip this step, as the CLI will be
automatically available as part of the Cloud Desktop environment.
Basic usage
cd into a Brazil package you want to review changes to.
Running cr -h will give you all the options that are supported by the CLI.
Examples
CLI examples
Reviews just the latest commit:
cr --parent HEAD^
Updates a review with this range of commits (exclusive:inclusive):
cr --include "MyService[7f07509:a261b4a],MyServiceModel[HEAD^]"
Any tree-ish can be used, including branch names for defining ranges:
cr --include "MyService[baseBranch:myBranch]"
review multiple packages:
cr -r CR-12345 -i "MyService[7f07509:a261b4a],MyServiceModel[HEAD^]"
Reviews just the latest commit and append it to existing CR:
cr --new-review
UI examples
Here is an example CR: https://code.amazon.com/reviews/CR-15521/revisions/1
See also
Using the CLI in the CRUX CLI Guide
Merging
EasyMergeService is the merge service that enables CRUX (code review tool for
internal Amazon developers) to merge code into a repository in GitFarm via Fast
Forward Merge, 3-Way Merge and Squash Merge APIs.
Merge options
Once you have all the approvals that you need and click on the Merge button, you
can choose one of the following merge types, depending on whether your commits are
fast-forwardable or not:
For non-fast-forwardable commits, you can choose either Rebase (default), Squash or
Three-way merge.
Additionally:
If the tip commit of your local branch (source) in the CR is behind the tip commit
of the remote branch (destination), then you can merge your commit using Squash or
Three-way merge.
You can choose a different merge type per package in the CR.
You can edit the commit message for the squashed and three-way commits if the
number of commits for that package is more than one (1).
You can squash all your fast-forwardable commits into one by using the Squash merge
option.
You can use the Three-way merge option to create a merge commit (previously the
only option for non-fast-forwardable commits).
Fast-forwardable commits
At the time of merging your commits on CRUX, if the history of your local branch
(source branch) is the same as the git history of the remote branch (destination
branch) that you are merging to, then those commits are fast-forwardable.
In other words, there is a linear path between your commits on your local history
and the remote branch.
Non-fast-forwardable commits
At the time of merging your commits on CRUX, if the history of your local branch
(source branch) is not the same as the git history of the remote branch
(destination branch) that you are merging to, then those commits are non-fast-
forwardable.
In other words, if the remote branch history has changed because someone else
pushed new commits before you attempted to merge your commits, then your commits
have become non-fast-forwardable.
Merge types
Fast-forward merge
If the commits are ref:fast-forwardable <concepts-fast-forwardable-commit>, then
the commits will be applied in order directly at the tip of the destination branch
without the need for a merge commit. This is known as a fast-forward merge.
Squash merges
A squash merge will attempt to merge all of the commits in the CR into a single
commit. It is similar to using git rebase or merging with the --squash option, but
there are differences you should be aware of.
If the individual commits to be “squashed” in a CR have the same author, then the
resulting squash commit will be authored by that person. Otherwise (if they have
different authors), the author of the merge commit will be the user who’s
performing the Merge. See Preserving author / committer information for more
information.
Rebase merges
A rebase merge will rewrite the commits in your CR on top of the destination
branch. This allows for a cleaner, more linear commit history than a 3-way merge.
Squash merge also accomplishes this, but rebase allows multiple commits from a
single CR to be preserved.
If all commits have the same author, then author = author of the commits.
If all commits have different authors, then author = requester of the merge.
If it’s a three-way merge with a merge commit, then the author = requester of the
merge.
Known limitations
For a CR with package that has a single commit to be reviewed, if the commit is
non-fast-forwardable, then the default merge option is squash-merge. If this option
is chosen and merged, the end result on your remote branch would be the same as it
would be in case of a rebase.
If you have multiple commits for that package, those commits will be squashed into
one single commit, before being merged to your remote branch.
EasyMergeService APIs are synchronous and stateless, but CRUX will make async
merge requests for each package. The corresponding API will merge these packages
independently and return the response to CRUX. If some of these packages fail, they
cannot stop the rest of the packages from being merged. If the failures are not due
to merge conflicts, they can be retried immediately.
Dry-run merge: no option exists to show the merge result before the actual push
We do not support dryrun merge capability because:
References in GitFarm cannot be deleted, resulting in adding more and more data to
the repository on each revision.
We would also end up spending a considerable amount of time to execute the merge
workflow on every revision to mostly get the same result as performing the actual
merge.
To avoid a slow merge workflow for customers, we decided the best approach for now
is to give the option to merge and report in case of failures.
CRUX Rules: EasyMerge does not automatically re-run a dry-run build before merging
squashed or 3-way merge commits
EasyMergeService does not re-run analyzers (for example, a dry-run build) before
merging the updated commit. EasyMergeService APIs are synchronous and stateless. As
a result, multiple dry-runs every time we attempt merging can cause too much
overload on the build requests, give rise to latencies and starve merge requests.
The principle is that your pipelines should have enough guardrails to prevent a
malicious commit from getting pushed to production. CRUX offers additional CRUX
rules that intends make this process easier and re-runs CRUX rules for every new
revision.
If you are really concerned about your build failing post squash or three-way merge
on the UI, we recommend you rebase locally and send a new revision. There is
ultimately no foolproof way to ensure every single commit that you merge will
successfully build on your pipeline despite the dry-runs.
Merge CR on top of another unmerged CR: cannot merge a commit whose parent is not
on the destination branch
Let’s say you have two commits, commitA --> commitB (commitA is the parent of
commitB). You created CR-A for commitA and you created another CR-B for commitB
using cr --parent HEAD. Then you cannot merge the CR-B because CR-A has not been
merged yet and as a result commitA is not on the destination branch yet. Since
these commits are linear, they will end up being fast-forward merged to the
destination branch resulting in an unreviewed commit being pushed.
The parent (base commit) of the commit(s) being reviewed is not found on the
destination branch. Please rebase locally.
See The parent (base commit) of the commit(s) being reviewed is not found on the
destination branch; Please rebase locally for info about responding to this error.
See also
Merging Code Reviews
Troubleshooting Merges
Note
CRUX is only available for GitFarm and is not supported with any other source code
management system.
General procedure
To create a new code review (CR) with CRUX:
Run the cr command from the git root where a code change is committed and follow
the output link. If you have more than one package in your workspace that you’d
like to have in the same review, then run cr from the src directory and use the --
include option to add each package individually, or the --all option to include any
package with un-pushed commits.
On the code review page, enter a summary and notes for the reviewers. Use
CommonMark to format the content and modify the description as required.
Names of people, teams, and groups will be autocompleted. Click a name or highlight
it and press Enter to add that person or group to the review. Autocomplete searches
for teams/groups by name and people by name, login, and role and is case-
insensitive. Groups auto-generated from Teams will only show the Team.
If you need to edit the summary or notes, access the Details tab and click on
Actions ‣ Edit Details. Both summary and description will be available for update.
Once you are satisfied with your summary, notes, and reviewers you can click
outside of this dialog to go straight to the diff.
Clicking Publish Review will send notifications to all of the reviewers so they can
come see it and leave comments.
At the moment you can create a code review for any diff compliant to any of these
formats:
Unified format
If you are using the diff tool, you must specify the number of lines of unified
context. To get the full context (required by CRUX) specify a number greater than
the number of lines in your file.
For individuals, click the Required switch to toggle its state. For groups,
increment or decrement the required number of Approvals.
Note
These actions can be performed by any user with permission to view the code review.
Create a team .
Edit the team ownership information to set its email alias to your desired email
list.
Note
The email alias associated with the team must be configured to allow external mail
in order to receive emails from CRUX.
If all the packages in the review are publicly readable, all CRUX emails will be
sent to the team email alias rather than dereferencing all the team members.
Favorite reviewers
You can favorite both people and groups, and they will then show up for you to
easily add them to a review. Favorited groups also control what reviews will show
up on your CR dashboard.
Favorite a group by clicking on the star next to its name while viewing your groups
.
Suggested reviewers
Suggested reviewers are available in case you don’t know what individual should
receive a review. Some teams prefer reviews to go to the entire group, while others
prefer reviews to go to an individual. It is common to “cc” a group, but also
identify a user who is expected to review the code. Having a declared reviewer
makes it more likely you will get a response quickly, instead of waiting for
someone to self elect.
Suggested reviewers are simply a random subset of the people who have write
permissions on the package. This is not an editable list. (We should arguably push
this content behind a click / hover, as the most common case is to send CRs to
people that you know well.)
You can use cr-pull to clone changes into a new Brazil workspace or an existing
one:
cr-pull CR-12345:3
See the documentation for cr-pull or type cr-pull --help for more information.
See the Brazil CLI Guide for more information about brazil ws snapshot.
Note
Only users in the source code permission group for the source packages in a CR can
perform a merge operation.
Perform a merge
A CR can be merged once it has received the required number of approvals and has
passed any configured CRUX Analyzer rules (such as Dry Run Build, InfoSecScan, and
so on).
Click Merge. The Merge request page displays and shows all packages that are going
to be merged. Each package must report a Ready to merge status.
Important
This is not intended as a common workflow, and you are required to enter a
justification for the override.
You must have write permissions on the package to Override & merge.
The Action menu with the Override & Merge operation highlighted.
You must provide a plaintext reason for the override before the Continue button
activates. If an analyzer on your code review has FAILED, you may also need to
select one of several override feedback categories.
The override modal view contains a dropdown to select a Coverlay override category.
Select Continue to proceed to the Merge screen.
Merge your changes using the options provided. All reviewers will be notified that
you used the override and the reason you gave.
Preventing merges
In some cases you may want to prevent commits from being merged, even when they’ve
received the required number of approvals, such as when you are waiting for a
particular condition / launch before merging the changes.
On the Details tab there is a checkbox labeled Allow reviewer to merge (pull
requests)?
If you uncheck this box, reviewers will not be able to merge your changes using
CRUX. You can change this box at any time, even after a CR is published.
On the Reviewers tab, add yourself as a required reviewer by typing your login in
the Add reviewer box.
Note
If you are already listed as a “watcher”, click this badge to flip yourself to be
“required” instead.
Your approval will have to be overridden for anybody else to merge the change.
Go to Bindles and open the Bindle to which you want to assign permissions.
In the Team name field, enter the name of the away-team and select Next Step.
Choose the Gitfarm Repository Permissions category and select Can approve Gitfarm
Repository.
The away-team should now be able to merge approved code reviews but will not be
able to git push changes directly.