Fix the shipped change list behind release notes

Review the AI's codeEasy12 min

Your task

An AI writes your release notes from the merged pull requests (PRs). Last release it announced a feature that was reverted before the release went out: it read the merge and not the revert. Your team now works out what shipped from the event stream before any notes are written. Each merge lands a change, and each revert takes one back out.

An assistant wrote net_shipped_titles(pr_events). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • pr_events: the release's events, in order, each written action|pr id|title. The title can contain |.
  • Return the titles of the PRs that shipped, ordered by PR id as a number, smallest first.

Rules the tests check:

  • Split an event at its first two |. Skip it when it has fewer than three parts. Trim whitespace from the action, the id and the title.
  • Skip the event unless the id is one or more digits from 0 to 9. Ids are numbers, so 007 and 7 are the same PR.
  • merge adds 1 to the PR's count and makes its title the PR's current title. revert subtracts 1. Any other action, like comment, changes nothing. Actions are case sensitive.
  • A PR shipped when its count is 1 or more after the last event. Use the title from its latest merge.

Examples

net_shipped_titles(pr_events: list[str]) -> list[str]
Example 1
Inputnet_shipped_titles(["merge|101|Add dark mode to the settings page", "merge|102|Speed up dashboard search", "revert|102|"])
Output["Add dark mode to the settings page"]
Example 2
Inputnet_shipped_titles(["comment|103|Dark mode across the dashboard is planned", "merge|104|Fix CSV export encoding"])
Output["Fix CSV export encoding"]
Example 3
Inputnet_shipped_titles(["merge|105|Add retry to webhook sender", "revert|105|", "merge|105|Add retry to webhook sender (fixed)"])
Output["Add retry to webhook sender (fixed)"]