Fix the shipped change list behind release notes
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 writtenaction|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
007and7are the same PR. mergeadds 1 to the PR's count and makes its title the PR's current title.revertsubtracts 1. Any other action, likecomment, 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
Input
net_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
Input
net_shipped_titles(["comment|103|Dark mode across the dashboard is planned", "merge|104|Fix CSV export encoding"])Output
["Fix CSV export encoding"]Example 3
Input
net_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)"]