Require a pull request before merging
Problem to solve
Protected branches in GitLab are implemented differently than in GitHub. For example, in GitHub there are some protected rules that you can apply on one or a few branches that match an expression, while those rules exist in GitLab as a general project settings for all branches. In this issue we make the mapping, so if a protected rule is defined in GH, and similar rule exists in GitLab general settings, we will configure the migrated GitLab project with this rule as a general settings, and this rule will be applied to all branches.
Purposed solution
Scenario: Require a pull request before merging When enabled, all commits must be made to a non-protected branch and submitted via a pull request before they can be merged into a branch that matches this rule.
Given "Require a pull request before merging When enabled, all commits must be made to a non-protected branch and submitted via a pull request before they can be merged into a branch that matches this rule." protected rule is defined in GitHub
When a user imports this repository to GitLab
Then in GitLab project settings, in the Allowed to merge list, Developers + Maintainers will be selected, and in the Allowed to push list, No one will be selected.
Technical details
Get branch protection rules from Github API. Look at required_pull_request_reviews
and map it's value into project.protected_branches.push_access_levels & project.protected_branches.merge_access_levels
associations.
Note: previously we decided to use the strictest set of branch protection rules (in this issue). So, if the imported protected branch is also protected in GitLab, we will apply the strictest rule for push_access_level/merge_access_level.
This pseudo code explains the logic of how exactly the mapping should be done here.
This flowchart shows how access_levels for imported protected branch are set: