My testing with other users didn’t change the behavior. Thanks to some of the existing issues (you linked some, thanks) I realized there’s actually an API to pull detailed MR approval information from https://host/api/v4/projects/project_id/merge_requests/mr_id/approvals
. It looks like this
{
"id": 58033,
"iid": 971,
"project_id": 924,
"title": "Testing code owners for MRs",
"description": "",
"state": "opened",
"created_at": "2021-08-03T17:26:40.142+02:00",
"updated_at": "2021-08-04T08:34:58.730+02:00",
"merge_status": "can_be_merged",
"approved": false,
"approvals_required": 1,
"approvals_left": 1,
"require_password_to_approve": false,
"approved_by": [],
"suggested_approvers": [
{
"id": 189,
"name": "***redacted-name***",
"username": "hef",
"state": "active",
"avatar_url": "https://***redacted-host***/uploads/-/system/user/avatar/189/avatar.png",
"web_url": "https://***redacted-host***/hef"
}
],
"approvers": [],
"approver_groups": [],
"user_has_approved": false,
"user_can_approve": false,
"approval_rules_left": [
{
"id": 44656,
"name": "All Members",
"rule_type": "any_approver"
}
],
"has_approval_rules": true,
"merge_request_approvers_available": true,
"multiple_approval_rules_available": false
}
What I read into it:
-
"approvals_required": 1
seems to match the “Any eligible user, 0 of 1” displayed on the GUI i.e. the MR approval rule unrelated to code owners
-
"suggested_approvers": []
is the one user I named in the code owners file for the affected artifact/path
-
"user_can_approve": false
bothers me a bit as it could indicate that GitLab thinks that the code owners user isn’t eligible to approve. This in turn could explain why the code owners approval is marked as optional in the GUI. Maybe? Just guessing.
I went on and also pulled the /projects/project_id/merge_requests/mr_id/approval_state
resource from the API.
{
"approval_rules_overwritten": true,
"rules": [
{
"id": 44656,
"name": "All Members",
"rule_type": "any_approver",
"eligible_approvers": [],
"approvals_required": 1,
"users": [],
"groups": [],
"contains_hidden_groups": false,
"section": null,
"source_rule": null,
"overridden": false,
"code_owner": false,
"approved_by": [],
"approved": false
},
{
"id": 44657,
"name": "/integration-messages/**/*.yaml",
"rule_type": "code_owner",
"eligible_approvers": [
{
"id": 189,
"name": "***redacted-name***",
"username": "hef",
"state": "active",
"avatar_url": "https://***redacted-host***/uploads/-/system/user/avatar/189/avatar.png",
"web_url": "https://***redacted-host***/hef"
}
],
"approvals_required": 0,
"users": [
{
"id": 189,
"name": "***redacted-name***",
"username": "hef",
"state": "active",
"avatar_url": "https://***redacted-host***/uploads/-/system/user/avatar/189/avatar.png",
"web_url": "https://***redacted-host***/hef"
}
],
"groups": [],
"contains_hidden_groups": false,
"section": "codeowners",
"source_rule": null,
"overridden": false,
"code_owner": true,
"approved_by": [],
"approved": true
}
]
}
This seems to dismiss my speculation from above. The second rule (44657 i.e. the code owner rule) says:
-
"eligible_approvers"
→ the one user listed in the code owners file → he actually is eligible to approve → no permission issues
-
"approvals_required": 0
→ WHY?