Google Professional Cloud Developer Question 244
Single answerGoogle Cloud PlatformYour team is using Cloud Source Repositories to manage your project's source code. A new policy requires that all changes to the main branch must be reviewed and approved before merging. How can you implement this policy effectively using Cloud Source Repositories?
- A
Enable branch protection on the main branch and configure it to require code reviews before merging.
- B
Use a CI/CD pipeline to reject any changes that are not reviewed.
- C
Manually review all changes before merging them into the main branch.
- D
Set up an IAM policy to restrict write access to the main branch.
Show answer and explanation
Correct answer: A
Explanation
Enabling branch protection on the main branch in Cloud Source Repositories is the most effective way to enforce the policy of requiring code reviews before merging. This feature allows you to programmatically enforce the review requirement, ensuring compliance with the policy while maintaining scalability and reliability.
- A. Correct.
This is the correct option because enabling branch protection in Cloud Source Repositories allows you to enforce code reviews before merging changes into the branch. This aligns with the policy requirement.
- B. Incorrect.
While a CI/CD pipeline can verify code quality or run tests, it does not enforce code reviews or approvals before merging changes into the main branch.
- C. Incorrect.
Manually reviewing changes is not an effective or scalable solution. It does not enforce the policy programmatically and can lead to human errors.
- D. Incorrect.
Restricting write access to the main branch with an IAM policy is useful, but it does not enforce a review process for changes before merging.