Let the bot request reviews through the platform
What does this MR do and why?
Adds the endpoint triage-ops calls when a contributor comments a bare @gitlab-bot ready on a merge request. The platform looks the merge request up, decides the next review step and posts the same note the manage merge request page posts, so the bot stops keeping its own copy of that logic. Commands with an explicit mention, including the hidden Duo line inside the note, stay in the bot.
The decision follows Duo's review state on the merge request.
- Duo is not a reviewer yet, so the note asks for a Duo review.
- Duo was asked but has not finished (unreviewed or review started), so the note asks the contributor to wait and request again later, with a link to the page for help. This note never mentions the bot, so it cannot start another request.
- Duo has reviewed, approved, requested changes or had its approval reset (unapproved), so the note asks the human reviewers already on the merge request again, leaving out Duo, the requester and the author. When there are none it asks the reviewer the picker suggests, with the author and the requester left out of the project candidates.
Counting unapproved as a finished review matches the page in !3063 (merged).
Builds on !3113 (merged), merged. The triage-ops side follows once this is deployed, link to come.
Design and production fit
The bot sends a Bearer token that the platform compares in constant time against a new TRIAGE_OPS_TOKEN setting, read from the Authorization header with the Rails helper. While that setting is blank every request gets 401, so the endpoint is inert until the token is in Vault and the bot starts calling it. Token and identifier checks run before anything else, and the controller checks both ids are integers before the lookup puts them in the query.
The lookup is one GraphQL call and the note is one REST write, neither retried, cause the bot gives up after 30 seconds and a retried write could post a note after the bot already posted its fallback. The answer is a bare 200 and the bot reads only the code. A failed lookup raises, so Rails logs the error and answers 500 and nothing is posted. A rejected note also answers 500, same as the page's own request review action today. A merge request the lookup cannot see answers 404. One it can see that is not public answers 422, like the page. When GitLab saved the note but the response got lost the platform cannot tell, so the bot's fallback wording allows for the note already being there.
The platform posts the note itself cause it is the note the page already posts under the platform account. Duo is still started through the hidden bot line in that note, since the platform's service account cannot start Duo flows. The waiting note is a second method on the note builder.
There is no rate limit on the platform side, the limit stays in the bot, 5 per hour for a bare @gitlab-bot ready from a contributor.
TRIAGE_OPS_TOKEN is documented in MAINTAINING.md.
Screenshots or screen recordings
No UI change.
Validation steps
The specs cover the token checks, the decisions, the lookup and the posted notes, and the regenerated OpenAPI file and API types are committed.
I ran it end to end on a local GDK with the real bot from the triage-ops branch and the real platform from this branch, a fresh merge request per scenario and the real @gitlab-bot ready comment. The GDK runs EE without a licence, so each merge request allows one reviewer. Where Duo already held the slot GitLab silently dropped the platform's /request_review @human, those rows read "reviewer write GDK-blocked". On gitlab.com multiple reviewers are allowed, which is the path the page already uses today.
GDK runs
| # | Scenario | GDK MR | Platform answer | Result on GDK |
|---|---|---|---|---|
| S1 | bare ready, no Duo |
472 | 200 duo_requested | PASS, platform Duo note with the hidden line, bot callback added GitLabDuo, MR ready, label set, no human pick note |
| S2 | Duo unreviewed | 473 | 200 duo_pending | PASS, pending note, reviewers unchanged, no bot mention in the note |
| S2b | Duo review started | 474 | 200 duo_pending | PASS, same as S2 |
| S3 | Duo reviewed | 476 | 200 human_requested | note names jaimie, reviewer write GDK-blocked |
| S4 | Duo approved | 477 | 200 human_requested | note names jaimie (approved counts as done), reviewer write GDK-blocked |
| S5 | Duo requested changes | 478 | 200 human_requested | note names jaimie, reviewer write GDK-blocked |
| S5b | Duo approved, then its state reset to unapproved | 475 | 200 human_requested | PASS, note names jaimie (unapproved counts as done), reviewer write GDK-blocked |
| S6 | Duo done, sabadi1 already a reviewer and marked reviewed | 481 | 200 human_requested | PASS on the decision, the note names sabadi1 only and the platform ran zero database queries, so the picker was not called. GitLab then removed the review request again because the unlicensed GDK allows one reviewer |
| S7 | Duo done, no project candidate, one coach | 480 | 200 human_requested | note names the coach sabadi1, reviewer write GDK-blocked, TeamMember rows restored |
| S8 | ready @jaimie |
482 | no call | PASS, bot path unchanged, jaimie requested by the bot, platform never called |
| S9 | platform stopped | 485 | connection refused | PASS, bot fallback note with the page link, no reviewer |
| S10 | bot with a wrong token | 486 | 401 | PASS, fallback note |
| S11 | platform without TRIAGE_OPS_TOKEN | 487 | 401 | PASS, fail closed, fallback note |
| S13 | team member sabadi1 types bare ready on phebe's MR, Duo done |
483 | 200 human_requested | PASS, note greets sabadi1 and names jaimie |
| S14 | bot in DRY_RUN | 488 | no call | PASS, would-be request logged, nothing posted |
| S15 | one MR, three ready in a minute, Duo set to reviewed in between |
484 | 200, 200, 200 | PASS, duo_requested then human_requested twice, nothing dropped by the limit of 5, reviewer write GDK-blocked |
| final | bare ready after every restore |
489 | 200 duo_requested | PASS, same as S1 |
After the review changes I ran twelve again on the final head, no Duo, Duo pending, Duo done with and without a human reviewer, a team member asking, an explicit mention, a wrong token, the platform without its token, the platform stopped, GitLab unreachable, a rejected note and a project that is not public, all as expected. The table above is from the first head, when the answer still carried a status word.
Two things worth knowing. The Duo only note carries the page's wording about coming back to the page for the human review, a second @gitlab-bot ready does the same. The bot marks the merge request ready and adds workflow::ready for review before asking the platform, so on the pending path and on failures the label is there while nothing was requested, same as today and kept on purpose.
This adds a new token authenticated endpoint, so I'd like a security review from @duo-security-review-gitlab-org.