Approve gitlab-merge-request's low ratings from the rating note

What does this MR do and why?

gitlab-bot approves gitlab-merge-request's merge requests on the MR Risk Labeler's low rating, read from the rating note the flow writes. This is the first approval step of item 4 in gitlab-org/gitlab#638236: approvals are verified on gitlab-merge-request first, where the rater runs on every merge request. It builds on !4543 (merged), now merged, which starts the flows' sessions on the project's default branch. gitlab-org/gitlab's approvals move to the rating in !4551 (merged), stacked on this one.

  • ReconcileApproval is a new processor for a project whose flow lists low_scopes. Each decision reads the merge request afresh, and approves only when all of these hold:

    • The merge request is open, not a draft, and not a community contribution.
    • The last comment the flow's account wrote on it is an internal note, never edited, whose last line is an mr-risk:v1 record of the head commit in live mode, with known rules. A later comment without a record leaves none standing. These are the reader rules in gitlab-merge-request!128's docs/specs/mr-risk.md.
    • The rating is low.
    • Every label the record names is on the merge request: gitlab-bot::<action>, each <area>-risk::<tier>, and gitlab-bot::risk::<tier>, which the flow's account added last.
    • None of the flow's excluded_labels is on the merge request.
    • The session the record names, workflow=, is one that TriggerReview started for this merge request: gitlab-bot's, in its project, after the head commit's diff version, and named by no other record. Every run of it is at a commit on the default branch. A session's job runs on a refs/workloads/ ref copied from the branch it started on, so the check reads the job's commit, not its ref.

    It approves at the rated commit, assigns gitlab-bot and posts an internal note. It decides again on any note the flow's account writes, when a label the record names is removed, when an excluded label or Community contribution is added, and when the merge request becomes a draft. A push withdraws the approval at once.

    A decision rests on what GitLab answered. A read that fails is made once more and then raised, so it neither approves nor withdraws. A session gitlab-bot cannot read is the one error that fails the check, because GitLab answers it with an error code of its own.

    In a project set to approve: false it logs what it would approve and approves nothing. It still withdraws an approval that no longer holds; only GITLAB_BOT_APPROVALS_ENABLED stops that.

  • Rating parses the record line, and nothing else.

  • Config: a flow can list low_scopes, only all for now. At most one flow per project lists them, and not a flow with categories. gitlab-merge-request gets approve: true and low_scopes: [all].

  • UnapproveOnDowngrade stands aside where a flow lists low_scopes, since ReconcileApproval withdraws there.

Nothing else changes: ApproveOnVerdict still approves gitlab-org/gitlab's categories.

Expected impact & dry-runs

  • Nothing approves until gitlab-merge-request rates in live mode, which is gitlab-merge-request!132.
  • gitlab-merge-request's approval policy needs a Maintainer or Owner. gitlab-bot's approval shows there, but does not count toward the policy until gitlab-bot's role or the policy changes.
  • The rating note is internal, so triage-ops has to receive gitlab-merge-request's internal notes. GitLab sends those under a webhook's confidential comments trigger. Whether the webhook that reaches triage-ops from that project has it on is still to confirm: without it no rating note arrives and nothing approves.
  • The record has to name its session. If DUO_WORKFLOW_WORKFLOW_ID does not reach the flow's record step, every record says workflow=unknown and nothing approves.
  • GitLab marks its note GraphQL query, which this reads the note's state from, as an experiment. If it changes, ratings stop verifying and nothing approves. Whether the note was edited is read from lastEditedBy, because GitLab answers lastEditedAt for a note nobody has edited.
  • Reads per decision: once every other check passes, a decision adds four kinds of read:
    • one GraphQL read of the rating note and its session;
    • a read of each of the session's jobs;
    • a merge-base read of each job's commit;
    • one project read.

How to set up and validate locally

SIMPLECOV=0 bundle exec rspec spec/processor/mr_approval_flow spec/triage/handler_spec.rb

The full suite passes: 7,904 examples, no failures.

🤖 Generated with Claude Code

Edited by Connor Sanders

Merge request reports

Loading
Loading