---
name: update-step-status
description: >
  Update the Status table on a plan's GitLab work item: set a step's MRs or
  status, then recompute which steps are blocked, ready for development, or
  blocked but can be stacked on one existing MR. Use for "update the status
  table on <work item url>", "mark steps 5, 8 as complete", "set !123 as the
  MR for step 6", "what's unblocked now", "refresh the blocked rows".
argument-hint: "<work item url> [what to set]"
---

# Step status table

Run `scripts/update-step-status.py` (stdlib Python, shells out to `glab api`). The URL
looks like `https://gitlab.com/<project>/-/work_items/<iid>`; ask for it when
`$ARGUMENTS` has none. A local file path works too and never writes.

The Status table is found by its `#`, `MR`, `Status` and `Dependencies` headers
(`Done` is optional), as an HTML `<table>` or a markdown pipe table. A write
keeps the table's own format: a pipe table stays a pipe table, and Done is
ticked as `[x]` there and `* [x]` in HTML. `no_table` means neither format has
those headers.

| Need | Command |
| --- | --- |
| Rows with status, MRs, open blockers | `update-step-status.py show <url>` |
| Set statuses and MRs | `update-step-status.py update <url> --status 5=complete --mr 6=!4308,!4309` |
| Recompute derived states | `update-step-status.py update <url> --refresh` |
| Preview any of these | add `--dry-run` |

`--status` takes `complete`, `in dev`, `in review`, `blocked` or
`ready for development`; `complete` also ticks Done. `--mr N=-` clears the cell.
`--status` and `--mr` apply first, then `--refresh`, so one call covers a
completion and its cascade.

A row id is a number with an optional letter (`6`, `6a`, `6b`). Each id is its
own row, with its own Status, MRs and Done cell, and `--status` and `--mr` take
the full id. A bare `6` matches only a row whose id is exactly `6`; with no such
row the call returns `no_step`. Any other id in the `#` column is an `error`.

## What `--refresh` does

First it queries GitLab for the MRs in each `in dev` or `in review` row and
marks the row `complete` (Done ticked) when every listed MR has merged. A row
with no MRs is left alone. Next it moves an `in dev` row to
`~"workflow::in review"` when any of its MRs is open and has a human reviewer
assigned. A bot is a user GitLab flags `bot: true` (GitLab Duo is one) or one in
the script's `BOTS` list, and it doesn't count. A draft MR counts like any other, and a closed or merged MR
doesn't. The move is one way: a reviewer removed later leaves the row in
review. Then it recomputes rows whose
Status is `blocked` or `ready for development`, so a merge cascades in one call.
Rows in dev, in review or complete are otherwise never changed.

| Row's open blockers | Result |
| --- | --- |
| none | `~"workflow::ready for development"` |
| one step, and that step has exactly one unmerged MR | `~"workflow::blocked" but can be stacked on !<MR>` |
| anything else | `~"workflow::blocked"` |

In Dependencies a lettered id counts as its number: `Step 6`, `Step 6a` and
`Step 6b` all name step 6, which is complete only when every row numbered 6 is.
So a row that depends on `6a` stays blocked while `6b` is open. A blocker whose
incomplete rows all hold MRs that have all merged (read from GitLab) no longer
blocks, even if its rows aren't marked complete. A blocker can be stacked on only
when its incomplete rows hold exactly one unmerged MR between them, so a step with
several MRs where one is still open is stacked on that one.

A blocker is a step in Dependencies that isn't complete. Text after a `;`, or a
cell with no `Step N`, is work outside the plan: it blocks (never ready, never
stackable) unless it says `merged` or `for ordering only`.

## Writing

Preview with `--dry-run` and show the user the `completed`, `in_review` and `refreshed` lists, then write.
Writing a GitLab work item needs the user's ask in the same turn. A step's
blocker with two or more unmerged MRs can't be stacked on, so its dependents stay plain blocked.

The script re-reads the description just before the PUT, aborts with
`changed` if it moved, and reads it back (`verify_failed` if it differs).
Other statuses: `ok`, `dry_run`, `no_table`, `no_step`, `bad_label`, `bad_arg`,
`bad_url`, `error`; report the `message`.

Overlaps `claim-step`, which sets Assignee and `in dev`; use that to claim and
this for everything else in the table.
