In this video, you’ll see how to improve the quality of your Java code using Amazon CodeGuru Reviewer.
With this service, you can detect potential defects, receive recommendations for code fixes,
and provide feedback to increase the effectiveness of future code analyses.
Amazon CodeGuru Reviewer is a service that uses program analysis and machine learning
to detect potential defects in Java code that are difficult for developers to find
and provides recommendations for fixing those defects.
To get started, navigate from the AWS Management Console to Amazon CodeGuru.
Next, select the CodeGuru Reviewer service and associate it with a code repository.
CodeGuru Reviewer connects to repositories such as GitHub, AWS CodeCommit,
and Bitbucket Cloud repositories.
For the purposes of this example, the code we want feedback on is stored in
an AWS CodeCommit repository.
The repository can be downloaded for the sample application at the URL shown on-screen.
After you select a repository to associate with CodeGuru,
it takes the service a few minutes to fully set up its resources.
Let’s refresh the view.
Before we make any changes in the code to invoke CodeGuru Reviewer comments,
let's look at the repository on CodeCommit, which should be in the same region as the CodeGuru service.
Select the repository.
Here, you can perform actions associated with the repository,
such as viewing files associatedwith different branches of a repo, creating a pull request,
getting links to clone a repo, and so forth.
Let’s go to the Settings page to ensure that this repository is properly associated
with CodeGuru Reviewer.
As you can see, the repository is associated.
Now let’s return to the Code page and open a terminal window so we can make changes to
the code and repository structure.
For the purposes of this example, the repository on CodeCommit is already associated with a
local git repository containing the code.
Let’s confirm this, using the command “git status.”
Notice that we are currently on the master branch of the repository.
Let’s use the “git checkout” command to create a new branch
where we can observe changes from the master branch.
We have now created and are working in a new branch called “codeguru-review.”
Let’s check to make sure.
As you can see, the current branch is “codeguru-review.”
Next, let’s open the code editor and apply some minor changes to the code in order to
invoke CodeGuru Reviewer comments.
Let’s modify this code to add a formatted date to the message that gets added to an
Amazon Simple Queue Service (SQS) queue.
Save the changes.
Now let’s commit the changes we've made to the codeguru-review branch
so we can receive commentary from CodeGuru Reviewer.
First, stage the changes.
Next, commit the changes.
Finally, push the changes to the new branch in CodeCommit.
Next, let’s go to the Commits section of the repository to ensure that all the changes
we made are reflected in CodeCommit.
Find the “codeguru-review” branch.
Let’s select the commit we just made to take a look.
Here you can see the changes we’ve made to the code.
To see the actual content of the code in the repository, select Browse file contents.
In order to see CodeGuru Reviewer comments, you must first invoke them through a pull request.
Let's create a request to pull changes from the codeguru-review branch into the master branch.
As you can see, the codeguru-review branch can be merged into the master branch.
Provide a title and create the pull request.
Updates to the pull request containing comments from CodeGuru Reviewer can take a while to show up.
In the mean time, let us look at the current Code Review entry status.
Here in the Code-reviews list view, we can see the history of the code reviews conducted earlier.
Each entry provides details about the past code reviews.
The current code review in progress is shown in the “Pending” state and will turn “Completed”
once the analysis is completed.
Let’s skip ahead in time to when the code review is completed.
Now, we’ll navigate back to the pull request that was created.
Navigate to the Activity tab to check for new comments.
As you can see, we’ve received a comment from the CodeGuru Reviewer bot about forgetting
to set the time zone when creating a code object containing the current date.
In other contexts, CodeGuru also provides comments about sensitive information
that might be displayed through the code repository, possible resource leaks,
and other potential deviations from best practices.
Let’s navigate to the Changes tab to see a comment in context.
Right from here, we can provide a comment in response to the CodeGuru recommendation.
We can also provide user feedback to the CodeGuru Reviewer service
to increase the effectiveness of future recommendations.
You’ve just seen how to improve the quality of your Java code using Amazon CodeGuru Reviewer.
Thanks for watching.
Now it’s your turn to try.