Skip to content

Instantly share code, notes, and snippets.

@shu85t
Created May 5, 2022 13:55
Show Gist options
  • Select an option

  • Save shu85t/3f4ab2ce0a34b904a8fc4e8f34c77e41 to your computer and use it in GitHub Desktop.

Select an option

Save shu85t/3f4ab2ce0a34b904a8fc4e8f34c77e41 to your computer and use it in GitHub Desktop.
CodeGuru Reviewer on CodeBuild
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