Skip to content

Check if default branch is already protected before creating

Sashi Kumar Kumaresan requested to merge sk/329422-protected-branch-check into master

What does this MR do?

As a part of #329422 (closed): while creating security policy project, the default branch should be protected and push_access_levels should have Gitlab::Access::NO_ACCESS. So we create protected branch for the default branch with push_access_levels.

Currently, BranchHooksService also creates a protected branch with default_branch_protection from the group that the project belongs to. This creates duplicate protected branches for the same default branch.

This change checks if the default branch is already protected before creating a protected branch. To avoid race condition from BranchHooksService, we update the branch protection for default branch if it already exists while creating security policy project.

Screenshots (strongly suggested)

Before:

Screenshot_2021-06-29_at_12.32.09_PM

After:

Screenshot_2021-06-22_at_4.08.08_PM

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Sashi Kumar Kumaresan

Merge request reports