Step 6: Clean up
After you're finished with this tutorial, clean up your resources.
1. In your GitHub fork of amazon-codeguru-reviewer-sample-app, go to Settings, and then choose Delete this repository. Follow the instructions to delete the forked repository.
2. Delete your clone of the forked repository, for example, rm -rf amazon-codeguru-reviewer-sample-app.
3. In the CodeGuru Reviewer console, select the example repository and choose Disassociate repository.
Working with repository associations in Amazon CodeGuru Reviewer
Amazon CodeGuru Reviewer requires a repository that contains the source code you want it to review.
To add a repository with your source code to CodeGuru Reviewer, you create a repository association.
When you associate a repository, you can enable a code review.
There are two different kinds of code reviews that CodeGuru Reviewer can do to provide recommendations.
• Pull request code reviews are created automatically when you create a pull request from your repository context on an associated repository. These code reviews scan the changed code in a pull request
• Repository analysis code reviews are done when you create a repository analysis code review in the CodeGuru Reviewer console. These code reviews scan all the code in a specified branch.
When you associate a repository, after it completes CodeGuru Reviewer performs its first full scan of the new associated repository for you. For more information, see About full repository analysis and incremental code reviews (p. 38).
If a repository contains Java and Python files, then CodeGuru Reviewer generates recommendations for the language for which there are more files. For example, if there are five Java files and ten Python files in an associated repository, then recommendations for the Python code are generated and no recommendations for the Java code are generated. If the number of Java and Python files is the same, then only Java recommendations are generated.
Immediately after you create the repository association, its status is Associating. A repository association with this status is doing the following.
• Setting up pull request notifications. This is required for pull requests to trigger a CodeGuru Reviewer review. For GitHub, GitHub Enterprise Server, and Bitbucket repositories, the notifications are
webhooks created in your repository to trigger CodeGuru Reviewer reviews. If you delete these webhooks, reviews of code in your repository cannot be triggered.
• Setting up source code access. This is required for CodeGuru Reviewer to securely clone the code in your repository.
When the pull request notifications, source code access, and creation of required permissions are complete, the status changes to Associated. After its status changes to Associated, the association is complete and you can create a pull request or a repository analysis to get recommendations.
CodeGuru Reviewer supports associations with repositories from the following source providers:
• AWS CodeCommit
• Bitbucket
• GitHub and GitHub Enterprise Cloud. These are listed together because you work with them identically using CodeGuru Reviewer.
• GitHub Enterprise Server
NoteThe source code reviewed by CodeGuru Reviewer is not stored. For more information, see the section called “Captured data” (p. 55).
Create a CodeCommit repository association
Topics
• Create an AWS CodeCommit repository association in Amazon CodeGuru Reviewer (p. 15)
• Create a Bitbucket repository association in Amazon CodeGuru Reviewer (p. 17)
• Create a GitHub or GitHub Enterprise Cloud repository association in Amazon CodeGuru Reviewer (p. 20)
• Create a GitHub Enterprise Server repository association in Amazon CodeGuru Reviewer (p. 21)
• View all repository associations in CodeGuru Reviewer (p. 24)
• Disassociate a repository in CodeGuru Reviewer (p. 25)
• Encrypting a repository association in Amazon CodeGuru Reviewer (p. 27)
• Tagging a repository association in Amazon CodeGuru Reviewer (p. 29)
Create an AWS CodeCommit repository association in Amazon CodeGuru Reviewer
You can create an AWS CodeCommit repository association using the Amazon CodeGuru Reviewer console, the AWS CodeCommit console, the AWS CLI, or the CodeGuru Reviewer SDK. Before you create a CodeCommit repository association, you must have a CodeCommit repository in the same AWS account and Region in which you want your CodeGuru Reviewer code reviews. For more information, see Create an AWS CodeCommit repository in the AWS CodeCommit User Guide.
Topics
• Create a CodeCommit repository association (CodeGuru Reviewer console) (p. 15)
• Create a CodeCommit repository association (CodeCommit console) (p. 16)
• Create a CodeCommit repository association (AWS CLI) (p. 16)
• Create a CodeCommit repository association (AWS SDKs) (p. 17)
Create a CodeCommit repository association (CodeGuru Reviewer console)
To create a CodeCommit repository association
1. Open the Amazon CodeGuru Reviewer console at https://console.aws.amazon.com/codeguru/
reviewer/home.
2. In the navigation pane, choose Repositories.
3. Choose Associate repository.
4. Choose AWS CodeCommit.
5. From Repository location, choose your CodeCommit repository.
6. (Optional) Expand Encryption key - optional to use your own AWS Key Management Service key (KMS key) to encrypt your associated repository. For more information, see Encrypting a repository association in Amazon CodeGuru Reviewer (p. 27).
a. Select Customize encryption settings (advanced).
b. Do one of the following:
• If you already have a KMS key that you manage, enter its Amazon Resource Name (ARN). For information about finding the ARN of your key using the console, see Finding the key ID and ARN in the AWS Key Management Service Developer Guide.
Create a CodeCommit repository association (CodeCommit console)
• If you want to create a KMS key, choose Create an AWS KMS key and follow the steps in the AWS KMS console. For more information, see Creating keys in the AWS Key Management Service Developer Guide.
7. In Run a repository analysis, specify information for your associated repository's first full scan. This scan generates your repository's initial code review. For more information, see Get recommendations using full repository analysis (p. 40).
a. From Source branch, choose the branch to use.
b. (Optional) In Code review name, type a name for your code review.
8. (Optional) Expand Tags to add one or more tags to your repository association. For more information, see Tagging a repository association in Amazon CodeGuru Reviewer (p. 29).
a. Choose Add new tag.
b. In Key, enter a name for the tag. You can add an optional value for the tag in Value.
c. (Optional) To add another tag, choose Add new tag.
9. Choose Associate repository and run analysis. On the Repositories page, the Status is Associating.
When the association is complete, the status changes to Associated and you can create a pull request or a repository analysis to get recommendations. Refresh the page to check for the status change.
Create a CodeCommit repository association (CodeCommit console)
You can connect to CodeGuru Reviewer directly from the CodeCommit console. This allows you to create a CodeCommit repository association with CodeGuru Reviewer without leaving your CodeCommit repository context.
Create a CodeCommit repository association (AWS CLI)
For information about using the AWS CLI with CodeGuru Reviewer, see the CodeGuru Reviewer section of the AWS CLI Command Reference.
To create a CodeCommit repository association
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create your code reviews and in which your CodeCommit repository exists. To verify the Region, run the following command at the command line or terminal and review the information for the default name.
aws configure
The default region name must match the AWS Region for the repository in CodeCommit.
2. Run the associate-repository command specifying the name of the CodeCommit repository you want to associate.
aws codeguru-reviewer associate-repository --repository CodeCommit={Name=my-codecommit-repo}
3. If successful, this command outputs a RepositoryAssociation object.
Create a CodeCommit repository association (AWS SDKs)
{ "RepositoryAssociation": {
"AssociationId": "repository-association-uuid", "Name": "my-codecommit-repo",
"LastUpdatedTimeStamp": 1595634764.029, "ProviderType": "CodeCommit",
"CreatedTimeStamp": 1595634764.029, "Owner": "123456789012",
"State": "Associating",
"StateReason": "Pending Repository Association", "AssociationArn": "arn:aws:codeguru-reviewer:us-west-2:123456789012:association:repository-association-uuid", }
}
4. When the associate-repository command succeeds, the status in the returned output is Associating.
When the association is complete, the status changes to Associated and you can create a pull request or a repository analysis to get recommendations. You can check your repository association's status using the describe-repository command with its Amazon Resource Name (ARN).
aws codeguru-reviewer describe-repository-association --association-arn
arn:aws:codeguru-reviewer:us-west-2:123456789012:association:repository-association-uuid
5. If successful, this command outputs a RepositoryAssociation object which shows its status.
{ "RepositoryAssociation": {
"AssociationId": "repository-association-uuid", "Name": "my-codecommit-repo",
"LastUpdatedTimeStamp": 1595634764.029, "ProviderType": "CodeCommit",
"CreatedTimeStamp": 1595634764.029, "Owner": "123456789012",
"State": "Associated",
"StateReason": ""Pull Request Notification configuration successful", "AssociationArn":
"arn:aws:codeguru-reviewer:us-west-2:123456789012:association:repository-association-uuid"
} }
Create a CodeCommit repository association (AWS SDKs)
To create a CodeCommit repository association with the AWS SDKs, use the AssociateRepository API. For more information, see AssociateRepository in the Amazon CodeGuru Reviewer API Reference.
Create a Bitbucket repository association in Amazon CodeGuru Reviewer
You can create a Bitbucket repository association using the Amazon CodeGuru Reviewer console, the AWS CLI, or the CodeGuru Reviewer SDK. Before you create a Bitbucket repository association, you must have a Bitbucket repository and you must create a connection to it using the Developer Tools console.
Create an AWS CodeCommit repository association (console)
For more information, see Create a connection in the Developer Tools User Guide. For information about creating a Bitbucket repository, see Create a Git repository on the Bitbucket website.
Topics
• Create a Bitbucket repository association (console) (p. 18)
• Create a Bitbucket repository association (AWS CLI) (p. 19)
• Create a Bitbucket repository association (AWS SDKs) (p. 20)
Create a Bitbucket repository association (console)
To create a Bitbucket repository association
1. Open the Amazon CodeGuru Reviewer console at https://console.aws.amazon.com/codeguru/
reviewer/home.
2. In the navigation pane, choose Repositories.
3. Choose Associate repository.
4. Choose Bitbucket.
5. From Connect to Bitbucket (with AWS CodeStar connections), choose the connection you want to use. If you don't have a connection, choose Create a Bitbucket connection to create one in the Developer Tools console. For more information, see Create a connection in the Developer Tools User Guide.
6. From Repository location, choose the name of your Bitbucket repository that contains the source code you want CodeGuru Reviewer to review.
7. From Repository location, choose your Bitbucket repository.
8. (Optional) Expand Encryption key - optional to use your own AWS Key Management Service key (KMS key) to encrypt your associated repository. For more information, see Encrypting a repository association in Amazon CodeGuru Reviewer (p. 27).
a. Select Customize encryption settings (advanced).
b. Do one of the following:
• If you already have a KMS key that you manage, enter its Amazon Resource Name (ARN). For information about finding the ARN of your key using the console, see Finding the key ID and ARN in the AWS Key Management Service Developer Guide.
• If you want to create a KMS key, choose Create an AWS KMS key and follow the steps in the AWS KMS console. For more information, see Creating keys in the AWS Key Management Service Developer Guide.
9. In Run a repository analysis, specify information for your associated repository's first full scan. This scan generates your repository's initial code review. For more information, see Get recommendations using full repository analysis (p. 40).
a. From Source branch, choose the branch to use.
b. (Optional) In Code review name, type a name for your code review.
10. (Optional) Expand Tags to add one or more tags to your repository association. For more information, see Tagging a repository association in Amazon CodeGuru Reviewer (p. 29).
a. Choose Add new tag.
b. In Key, enter a name for the tag. You can add an optional value for the tag in Value.
c. (Optional) To add another tag, choose Add new tag.
11. Choose Associate repository and run analysis. On the Repositories page, the Status is Associating.
When the association is complete, the status changes to Associated and you can create a pull
Create a Bitbucket repository association (AWS CLI)
request or a repository analysis to get recommendations. Refresh the page to check for the status change.
Create a Bitbucket repository association (AWS CLI)
For information about using the AWS CLI with CodeGuru Reviewer, see the CodeGuru Reviewer section of the AWS CLI Command Reference
To create a Bitbucket repository association
1. Make sure that you have configured the AWS CLI with the AWS Region in which you want to create your code reviews. To verify the Region, run the following command at the command line or terminal and review the information for the default name.
aws configure
The default Region name must match the AWS Region for the repository in CodeCommit.
2. Run the associate-repository command specifying the owner (or user name) of your Bitbucket account, the name of your repository, and the Amazon Resource Name (ARN) of your connection.
aws codeguru-reviewer associate-repository --repository Bitbucket="{Owner=bitbucket-user-name, Name=repository-name, \
ConnectionArn=arn:aws:codestar-connections:us-west-2:123456789012:connection/
repository-uuid }"
3. If successful, this command outputs a RepositoryAssociation object.
{
"RepositoryAssociation": { "ProviderType": "Bitbucket", "Name": "repository-name",
"LastUpdatedTimeStamp": 1595886585.96,
"AssociationId": "repository_association_uuid", "CreatedTimeStamp": 1595886585.96,
"ConnectionArn": "arn:aws:codestar-connections:us-west-2:123456789012:connection/connection_uuid",
"State": "Associating",
"StateReason": "Pending Repository Association", "AssociationArn": "arn:aws:codeguru-reviewer:us-west-2:123456789012:association:repository-association-uuid", "Owner": "bitbucket-user-name"
} }
4. When the associate-repository command succeeds, the status in the returned output is Associating.
When the association is complete, the status changes to Associated and you can create a pull request or a repository analysis to get recommendations. You can check your repository association's status using the describe-repository command with its Amazon Resource Name (ARN).
aws codeguru-reviewer describe-repository-association --association-arn
arn:aws:codeguru-reviewer:us-west-2:123456789012:association:repository-association-uuid
5. If successful, this command outputs a RepositoryAssociation object which shows its status.
{ "RepositoryAssociation": {
Create a Bitbucket repository association (AWS SDKs)
"ProviderType": "Bitbucket", "Name": "repository-name",
"LastUpdatedTimeStamp": 1595886585.96,
"AssociationId": "repository_association_uuid", "CreatedTimeStamp": 1595886585.96,
"ConnectionArn": "arn:aws:codestar-connections:us-west-2:123456789012:connection/connection_uuid",
"State": "Associated",
"StateReason": ""Pull Request Notification configuration successful", "AssociationArn":
"arn:aws:codeguru-reviewer:us-west-2:123456789012:association:repository-association-uuid", "Owner": "bitbucket-user-name"
} }
Create a Bitbucket repository association (AWS SDKs)
To create a Bitbucket repository association with the AWS SDKs, use the AssociateRepository API.
For more information, see AssociateRepository in the Amazon CodeGuru Reviewer API Reference.
Create a GitHub or GitHub Enterprise Cloud repository association in Amazon CodeGuru Reviewer
You can create a GitHub or GitHub Enterprise Cloud repository association using the Amazon CodeGuru Reviewer console. You cannot create a GitHub or GitHub Enterprise Cloud repository association using the AWS CLI or the CodeGuru Reviewer SDK. Before you create a GitHub or GitHub Enterprise Cloud repository association, you must have a GitHub or GitHub Enterprise Cloud repository.
NoteWe recommend creating a new GitHub user (for example, MyCodeGuruUser) and using that user to provide CodeGuru Reviewer with access to your GitHub repositories. This ensures that CodeGuru Reviewer posts comments on behalf of a unique user. This helps avoid confusion and make the account more transferable, so that it doesn't belong to a single person who might not always be available to maintain it.
To create a GitHub repository association
1. Open the Amazon CodeGuru Reviewer console at https://console.aws.amazon.com/codeguru/
reviewer/home.
2. In the navigation pane, choose Repositories.
3. Choose Associate repository.
4. Choose GitHub.
5. If you are not connected to GitHub, choose Connect to GitHub and follow the prompts to connect.
6. From Repository location, choose your repository.
7. (Optional) Expand Encryption key - optional to use your own AWS Key Management Service key (KMS key) to encrypt your associated repository. For more information, see Encrypting a repository association in Amazon CodeGuru Reviewer (p. 27).
a. Select Customize encryption settings (advanced).
Create a GitHub Enterprise Server repository association
b. Do one of the following:
• If you already have a KMS key that you manage, enter its Amazon Resource Name (ARN). For information about finding the ARN of your key using the console, see Finding the key ID and ARN in the AWS Key Management Service Developer Guide.
• If you want to create a KMS key, choose Create an AWS KMS key and follow the steps in the AWS KMS console. For more information, see Creating keys in the AWS Key Management Service Developer Guide.
8. In Run a repository analysis, specify information for your associated repository's first full scan. This scan generates your repository's initial code review. For more information, see Get recommendations using full repository analysis (p. 40).
a. From Source branch, choose the branch to use.
b. (Optional) In Code review name, type a name for your code review.
9. (Optional) Expand Tags to add one or more tags to your repository association. For more information, see Tagging a repository association in Amazon CodeGuru Reviewer (p. 29).
a. Choose Add new tag.
b. In Key, enter a name for the tag. You can add an optional value for the tag in Value.
c. (Optional) To add another tag, choose Add new tag.
10. Choose Associate repository and run analysis. On the Repositories page, the Status is Associating.
When the association is complete, the status changes to Associated and you can create a pull request or a repository analysis to get recommendations. Refresh the page to check for the status change.
Create a GitHub Enterprise Server repository association in Amazon CodeGuru Reviewer
You can create a GitHub Enterprise Server repository association using the Amazon CodeGuru Reviewer console, the AWS CLI, or the CodeGuru Reviewer SDK. Before you create a GitHub Enterprise Server repository association, you must have a GitHub Enterprise Server repository.
Note
GitHub Enterprise Cloud repositories have a different procedure and different prerequisites. If you're using GitHub Enterprise Cloud, follow this procedure instead.
Topics
• GitHub Enterprise Server repository association prerequisites (p. 21)
• Create a GitHub Enterprise Server repository association (console) (p. 22)
• Create a GitHub Enterprise Server repository association (AWS CLI) (p. 23)
• Create a GitHub Enterprise Server repository association (AWS SDKs) (p. 24)
GitHub Enterprise Server repository association prerequisites
To create a GitHub Enterprise Server repository association, you must have a GitHub Enterprise Server connection in AWS CodeStar connections. The connection must be in the same AWS account and Region in which you want your code reviews. For more information, see Create a connection and Create a connection to GitHub Enterprise Server in the Developer Tools User Guide.
Create a GitHub Enterprise Server repository association (console) Important
AWS CodeStar connections does not support GitHub Enterprise Server version 2.22.0 due to a known issue in the release. To create a connection, use version 2.22.1 or later.
Your GitHub Enterprise Server connection requires a host. The host represents your GitHub Enterprise Server instance and is to what your GitHub Enterprise Server connection connects. A host can be an on-premises server or a Virtual Private Cloud (VPC). For more information, see Amazon VPC configuration for your host and Create a host in the AWS Developer Tools User Guide.
Create a GitHub Enterprise Server repository association (console)
To create a GitHub Enterprise Server repository association
1. Open the Amazon CodeGuru Reviewer console at https://console.aws.amazon.com/codeguru/
reviewer/home.
2. In the navigation pane, choose Repositories.
3. Choose Associate repository.
4. Choose GitHub Enterprise Server.
5. From Connect to GitHub Enterprise Server (with AWS CodeStar Connections), choose the connection you want to use. If you don't have a connection, choose Create a GitHub Enterprise Server connection to create one in the Developer Tools console. For more information, see Create a connection in the AWS Developer Tools User Guide.
6. From Repository location, choose the GitHub Enterprise Server repository.
7. (Optional) Expand Encryption key - optional to use your own AWS Key Management Service key (KMS key) to encrypt your associated repository. For more information, see Encrypting a repository association in Amazon CodeGuru Reviewer (p. 27).
a. Select Customize encryption settings (advanced).
b. Do one of the following:
• If you already have a KMS key that you manage, enter its Amazon Resource Name (ARN). For information about finding the ARN of your key using the console, see Finding the key ID and ARN in the AWS Key Management Service Developer Guide.
• If you want to create a KMS key, choose Create an AWS KMS key and follow the steps in the AWS KMS console. For more information, see Creating keys in the AWS Key Management Service Developer Guide.
8. In Run a repository analysis, specify information for your associated repository's first full scan. This scan generates your repository's initial code review. For more information, see Get recommendations using full repository analysis (p. 40).
a. From Source branch, choose the branch to use.
b. (Optional) In Code review name, type a name for your code review.
9. (Optional) Expand Tags to add one or more tags to your repository association. For more information, see Tagging a repository association in Amazon CodeGuru Reviewer (p. 29).
9. (Optional) Expand Tags to add one or more tags to your repository association. For more information, see Tagging a repository association in Amazon CodeGuru Reviewer (p. 29).