Watch
0
0
Fork
You've already forked hyperhive
0

review-classifier: skip draft prs, classify once when they leave draft

This commit is contained in:
atlas 2026-11-02 17:58:22 +01:00 • committed by mara
commit 49ef93a19e

View file

@ -221,6 +221,8 @@ mod tests {
("number", text("7")),
("title", text("router")),
("url", text("https://forge/7")),
("draft", text("false")),
("undrafted", text("false")),
("assignees_added", list(added)),
("assignees_removed", list(removed)),
("todo_holders", list(holders)),
@ -458,6 +460,44 @@ mod tests {
assert_eq!(got("pull_request_assign", "opened"), 0);
}
/// A draft PR gets no request on open, reopen or push; the edit that takes
/// it out of draft gets exactly one, and a title edit that does not does not.
#[test]
fn the_classifier_flow_skips_a_draft_and_requests_once_when_it_leaves_draft() {
let f = swarm_wire::notify_flows::builtins()
.into_iter()
.find(|f| f.id == "head-classifier")
.expect("the built-in");
let pull = |action: &str, draft: bool, undrafted: bool| {
let mut fields = event(action, &[], &[], &[]);
fields.insert("kind", text("PR"));
fields.insert("draft", text(if draft { "true" } else { "false" }));
fields.insert("undrafted", text(if undrafted { "true" } else { "false" }));
fields
};
let got = |event_type: &str, fields: &Fields| requests(&f, event_type, fields);
for (event_type, action) in [
("pull_request", "opened"),
("pull_request", "reopened"),
("pull_request_sync", "synchronized"),
] {
assert!(
got(event_type, &pull(action, true, false)).is_empty(),
"{action}"
);
assert_eq!(
got(event_type, &pull(action, false, false)).len(),
1,
"{action}"
);
}
let left = got("pull_request", &pull("edited", false, true));
assert_eq!(left.len(), 1);
assert_eq!(left[0].node, "request-undrafted");
assert!(got("pull_request", &pull("edited", false, false)).is_empty());
assert!(got("pull_request", &pull("edited", true, false)).is_empty());
}
#[test]
fn a_placeholder_expands_to_its_field_and_an_unknown_one_is_an_error() {
let fields = event("assigned", &["a", "b"], &[], &[]);