Approvals left is miscalculated by counting all matching CODEOWNER rules
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Proposal
When a CODEOWNERS file is used, the merge request UI shows a number of approvals required based on the number of matching rules in the CODEOWNERS file, which does not necessarily correspond to the actual number of approvals required, which is a confusing discrepancy to MR authors and reviewers.
For example, consider a MR is created which matches 20 different CODEOWNERS rules, but they all have the same set of approvers. The UI will claim 20 separate approvals are required, when in reality only 1 approval is actually required since they all target the same approvers.
For another example, consider a MR which again matches 20 different rules, but this time 10 rules target one set of approvers and the other 10 rules target a different set of approvers. The UI will still claim 20 separate approvals are required, but in this case 2 approvals are required since there are 2 different sets of matching approvers.
The root issue here is that number of approvals required is calculated by counting the number of matching CODEOWNERS rules without considering that some rules may have the same approvers. If matching rules were to be deduplicated by distinct sets of approvers before counting, this would produce the expected result where the UI displayed number of approvals required corresponds to the number of distinct sets of matching approvers, and not the number of matching rules.
Relevant code:
def approvals_left
strong_memoize(:approvals_left) do
[regular_rules_left + code_owner_rules_left + report_approver_rules_left, any_approver_rules_left].max
end
end