Choose which review comments an agent may post
Your task
An agent does a first pass on every pull request before a person reviews it. It drafts more comments than anyone wants to read, so a filter decides which ones get posted.
Write select_pr_comments(comments, max_comments, min_severity): the rule your agent follows to choose what to post.
comments(list of str): the agent's draft comments, each writtencategory|severity|id, for example"missing-tests|8|c1".max_comments(int): the most comments one pull request may get.min_severity(int): the lowest severity worth posting.- Return the ids of the comments to post, in the order they are posted.
Rules:
- Split each draft on
|. One that does not have exactly 3 fields is dropped. - Drop it unless its category is exactly
missing-tests,dead-code,null-handlingordoc-mismatch. Fields are used as written, with no trimming, and case matters:Missing-Testsis dropped. - Drop it unless its severity is one or more digits, 0 to 9 only. So
x,-1and an empty severity are dropped. - Drop it if its severity is below
min_severity. A severity equal tomin_severitystays. - Post at most
max_commentsof the rest, highest severity first. Drafts with equal severity keep their input order. Amax_commentsof 0 or less posts nothing.
Ids come back exactly as written, repeats included.
Examples
select_pr_comments(comments: list[str], max_comments: int, min_severity: int) -> list[str]Example 1
Input
select_pr_comments(["missing-tests|8|c1", "architecture|9|c2", "dead-code|5|c3", "naming|7|c4", "null-handling|6|c5"], 5, 4)Output
["c1", "c5", "c3"]Example 2
Input
select_pr_comments(["doc-mismatch|3|d1", "missing-tests|9|d2"], 5, 4)Output
["d2"]Example 3
Input
select_pr_comments(["missing-tests|4|a", "dead-code|9|b", "null-handling|7|c", "doc-mismatch|6|d", "missing-tests|8|e", "dead-code|5|f"], 3, 1)Output
["b", "e", "c"]