Created
May 5, 2022 13:55
-
-
Save shu85t/3f4ab2ce0a34b904a8fc4e8f34c77e41 to your computer and use it in GitHub Desktop.
CodeGuru Reviewer on CodeBuild
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| echo "Start CodeGuru review" | |
| # create review | |
| type_param=$(cat << EOS | |
| { | |
| "RepositoryAnalysis": { | |
| "RepositoryHead": {"BranchName": "${REPOSITORY_BRANCH}"} | |
| }, | |
| "AnalysisTypes": ["Security", "CodeQuality"] | |
| } | |
| EOS | |
| ) | |
| review_arn=`aws codeguru-reviewer create-code-review \ | |
| --name ${CODEBUILD_BUILD_ID//:/_} \ | |
| --repository-association-arn $CODEGURU_REVIEWER_ASSOCIATION_ARN \ | |
| --type "${type_param}" \ | |
| --query "CodeReview.CodeReviewArn" --output text` | |
| echo "Create review_arn=" $review_arn | |
| # wait | |
| echo "Wait..." | |
| aws codeguru-reviewer wait code-review-completed --code-review-arn $review_arn | |
| # count recommendations | |
| recommendations_count=$(aws codeguru-reviewer describe-code-review --code-review-arn $review_arn \ | |
| --query "CodeReview.Metrics.FindingsCount" --output text) | |
| echo "recommendations count=" $recommendations_count | |
| echo "Show Details https://${AWS_REGION}.console.aws.amazon.com/codeguru/reviewer/codereviews/details/${review_arn}" | |
| # assert | |
| if [[ "$recommendations_count" = "0" ]]; then | |
| echo "OK: Has no recommendations" | |
| exit 0 | |
| else | |
| echo "NG: Has ${recommendations_count} recommendations" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment