Watch
0
0
Fork
You've already forked hyperhive
0

request the review classifier when a pr is opened or reopened

This commit is contained in:
atlas 2026-10-28 03:31:38 +01:00 • committed by mara
commit b1a00a3222
3 changed files with 110 additions and 38 deletions

View file

@ -118,7 +118,7 @@ mod tests {
assert_eq!(count(&r, "closed", "sink"), 1);
// No pull request push: the classifier flow counts zero.
assert_eq!(count(&r, "head-classifier", "source"), 0);
assert_eq!(count(&r, "head-classifier", "request"), 0);
assert_eq!(count(&r, "head-classifier", "request-opened"), 0);
}
/// A condition on a field that depends on the previous event of the

View file

@ -435,6 +435,29 @@ mod tests {
assert!(evaluate(&f, "pull_request_sync", &pull("assigned", "PR")).is_empty());
}
/// The built-in classifier flow requests on a push, an open and a reopen,
/// and on no other action of a `pull_request` event.
#[test]
fn the_classifier_flow_requests_on_open_reopen_and_push_only() {
let f = swarm_wire::notify_flows::builtins()
.into_iter()
.find(|f| f.id == "head-classifier")
.expect("the built-in");
assert_eq!(f.validate(), Ok(()));
let pull = |action: &str| {
let mut fields = event(action, &[], &[], &[]);
fields.insert("kind", text("PR"));
fields
};
let got = |event_type: &str, action: &str| requests(&f, event_type, &pull(action)).len();
assert_eq!(got("pull_request", "opened"), 1);
assert_eq!(got("pull_request", "reopened"), 1);
assert_eq!(got("pull_request_sync", "synchronized"), 1);
assert_eq!(got("pull_request", "closed"), 0);
assert_eq!(got("pull_request", "edited"), 0);
assert_eq!(got("pull_request_assign", "opened"), 0);
}
#[test]
fn a_placeholder_expands_to_its_field_and_an_unknown_one_is_an_error() {
let fields = event("assigned", &["a", "b"], &[], &[]);

View file

@ -212,7 +212,7 @@ mod tests {
r.requests,
[ReviewRequest {
flow: "head-classifier".to_owned(),
node: "request".to_owned(),
node: "request-synchronized".to_owned(),
repo: "o/r".to_owned(),
number: 9,
reviewer: "review-classifier".to_owned(),
@ -222,10 +222,19 @@ mod tests {
assert_eq!(r.next, before);
// The source gates: another PR event requests nothing.
for other in ["pull_request", "pull_request_assign", "issues"] {
for other in ["pull_request_assign", "issues"] {
let r = route(other, &pull, &before, &flows, |_| true);
assert!(r.requests.is_empty(), "{other}");
}
// Opening a PR is one `pull_request` event with action `opened`.
let opened = Delivery {
is_pull: true,
..delivery("opened", &[])
};
let r = route("pull_request", &opened, &before, &flows, |_| false);
assert_eq!(r.requests.len(), 1);
assert_eq!(r.requests[0].node, "request-opened");
assert!(r.actions.is_empty() && r.skipped.is_empty());
// Only a PR can be asked to review.
let issue = delivery("synchronized", &[]);
let r = route("pull_request_sync", &issue, &before, &flows, |_| true);