GitLab: reviewers config doesn't stop Automatic reviewer assignment (CODEOWNERS) because createPr() sets reviewer_ids after MR creation, not during #45473
Unanswered
shubhamdhingra007
asked this question in
Request Help
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
What are you trying to do?
On GitLab, we enabled Automatic reviewer assignment (
reviewer_assignment_strategy: code_owners) so that CODEOWNERS get auto-added as reviewers on human PRs, but not on Renovate's dependency-update MRs — the docs say GitLab skips the auto-assignment when "the merge request already has a reviewer", so we set Renovate'sreviewersconfig expecting that to satisfy the skip condition.It doesn't. Every Renovate MR still gets the full CODEOWNERS reviewer list added on top of our configured
reviewers.Current behavior
Every Renovate-created MR on a project with a
CODEOWNERSfile andreviewer_assignment_strategy: code_ownersends up with all CODEOWNERS-matched reviewers plus whatever is inreviewers/reviewersFromCodeOwners— even thoughreviewersis set.Root cause we traced
createPr()creates the MR viaPOST /merge_requestswithoutreviewer_ids:Reviewers are only added afterward, in a separate call from
addReviewers(), invoked later viaaddParticipantsinlib/workers/repository/update/pr/index.ts:Because the MR is created in ready (non-draft) state with zero reviewers, GitLab's own Automatic reviewer assignment sees "MR created in ready state" + "no reviewer yet" and immediately assigns every CODEOWNERS match — before Renovate's separate
addReviewers()call ever runs. By the time that call executes, it fetches the already-populated reviewer list and just appends our configured reviewers on top. The MR is never in a state where it "already has a reviewer" at the moment GitLab's skip-check runs.Confirmed this isn't specific to Renovate's reviewer handling: we checked two MRs authored directly by a human (no Renovate involvement, no reviewer config at all) on the same project — the exact same CODEOWNERS reviewer list gets added within ~2 seconds of MR creation, via a system note attributed to the MR author. This rules out anything about how Renovate resolves
reviewers/reviewersFromCodeOwners; it's purely about when a reviewer exists relative to MR creation.Expected behavior
If
reviewers(orreviewersFromCodeOwners) is configured, Renovate should include the resolvedreviewer_idsinline in thePOST /merge_requestscall that creates the MR, so the MR is never created with zero reviewers, and GitLab's documented skip condition can actually apply.Reproduction
A throwaway public-repo reproduction isn't practical here, because Automatic reviewer assignment is a GitLab Premium/Ultimate-tier project setting, which a free public GitLab.com repo can't enable. To reproduce on a Premium/Ultimate namespace:
CODEOWNERSfile matching all files, e.g.* @some-group."reviewers": ["some-other-user"].some-other-user.Happy to share sanitized evidence from our real-world case (GitLab API responses for
merge_requests/:iid,/approval_state, projectreviewer_assignment_strategy, and system-note timestamps) if that helps confirm the timeline — omitted here for confidentiality.Suggested fix
Resolve reviewer usernames/group members to IDs (the logic already exists in
addReviewers/expandGroupMembers) before callingplatform.createPr()on GitLab, and passreviewer_idsin the initialPOST /merge_requestsbody instead of doing it as a separate post-creation call.Happy to put together a PR if maintainers are open to this — would appreciate guidance on the preferred shape, since it touches the shared
createPr/addParticipantsordering inlib/workers/repository/update/pr/index.ts, not just the GitLab-specific file.Disclosure: this report was investigated with AI assistance (root-cause tracing and code search), reviewed and verified against live GitLab API responses by a human before posting.
All reactions