request the review classifier when a pr is opened or reopened
This commit is contained in:
parent
668bd5d46c
commit
b1a00a3222
1 changed files with 110 additions and 38 deletions
|
|
@ -771,7 +771,8 @@ impl TodoSink {
|
|||
/// then tells each agent that held one with a `closed` todo. The clear is the
|
||||
/// first child of the match and runs first: its prefix also covers the
|
||||
/// `closed` key.
|
||||
/// - `head-classifier`: a push to a PR requests the review classifier's review.
|
||||
/// - `head-classifier`: a PR opened, reopened or pushed to requests the review
|
||||
/// classifier's review.
|
||||
#[must_use]
|
||||
pub fn builtins() -> Vec<Flow> {
|
||||
let assignment_key = "forge:{repo}#{number}:assignment";
|
||||
|
|
@ -837,30 +838,48 @@ fn closed() -> Flow {
|
|||
flow
|
||||
}
|
||||
|
||||
/// source(`pull_request_sync`) → request the review classifier's review.
|
||||
/// source(`pull_request`, `pull_request_sync`) → match(`action` = `opened`,
|
||||
/// `reopened` or `synchronized`) → request the review classifier's review.
|
||||
fn head_classifier() -> Flow {
|
||||
let mut nodes = vec![Node {
|
||||
id: "source".to_owned(),
|
||||
kind: NodeKind::Source {
|
||||
events: vec!["pull_request".to_owned(), "pull_request_sync".to_owned()],
|
||||
},
|
||||
}];
|
||||
let mut edges = Vec::new();
|
||||
for action in ["opened", "reopened", "synchronized"] {
|
||||
let (matched, request) = (format!("match-{action}"), format!("request-{action}"));
|
||||
nodes.push(Node {
|
||||
id: matched.clone(),
|
||||
kind: NodeKind::Match {
|
||||
when: vec![Condition {
|
||||
field: "action".to_owned(),
|
||||
equals: action.to_owned(),
|
||||
}],
|
||||
},
|
||||
});
|
||||
nodes.push(Node {
|
||||
id: request.clone(),
|
||||
kind: NodeKind::RequestReviewer {
|
||||
reviewer: CLASSIFIER_ACCOUNT.to_owned(),
|
||||
},
|
||||
});
|
||||
edges.push(Edge {
|
||||
from: "source".to_owned(),
|
||||
to: matched.clone(),
|
||||
});
|
||||
edges.push(Edge {
|
||||
from: matched,
|
||||
to: request,
|
||||
});
|
||||
}
|
||||
Flow {
|
||||
id: "head-classifier".to_owned(),
|
||||
name: "head-classifier".to_owned(),
|
||||
enabled: true,
|
||||
nodes: vec![
|
||||
Node {
|
||||
id: "source".to_owned(),
|
||||
kind: NodeKind::Source {
|
||||
events: vec!["pull_request_sync".to_owned()],
|
||||
},
|
||||
},
|
||||
Node {
|
||||
id: "request".to_owned(),
|
||||
kind: NodeKind::RequestReviewer {
|
||||
reviewer: CLASSIFIER_ACCOUNT.to_owned(),
|
||||
},
|
||||
},
|
||||
],
|
||||
edges: vec![Edge {
|
||||
from: "source".to_owned(),
|
||||
to: "request".to_owned(),
|
||||
}],
|
||||
nodes,
|
||||
edges,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1214,24 +1233,42 @@ mod tests {
|
|||
assert!(matches!(node.kind, NodeKind::RequestReviewer { .. }));
|
||||
}
|
||||
|
||||
/// The built-in that requests the classifier on every push.
|
||||
/// The built-in that requests the classifier on an open, a reopen and a push.
|
||||
#[test]
|
||||
fn head_classifier_requests_the_classifier_on_a_push() {
|
||||
fn head_classifier_requests_the_classifier_on_open_reopen_and_push() {
|
||||
let f = builtin("head-classifier");
|
||||
assert_eq!(f.validate(), Ok(()));
|
||||
assert_eq!(
|
||||
f.nodes[0].kind,
|
||||
NodeKind::Source {
|
||||
events: vec!["pull_request_sync".to_owned()]
|
||||
events: vec!["pull_request".to_owned(), "pull_request_sync".to_owned()]
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
f.nodes[1].kind,
|
||||
NodeKind::RequestReviewer {
|
||||
reviewer: CLASSIFIER_ACCOUNT.to_owned()
|
||||
}
|
||||
f.children("source"),
|
||||
["match-opened", "match-reopened", "match-synchronized"]
|
||||
);
|
||||
assert_eq!(f.children("source"), ["request"]);
|
||||
for action in ["opened", "reopened", "synchronized"] {
|
||||
assert_eq!(
|
||||
f.node(&format!("match-{action}")).map(|n| &n.kind),
|
||||
Some(&NodeKind::Match {
|
||||
when: vec![Condition {
|
||||
field: "action".to_owned(),
|
||||
equals: action.to_owned()
|
||||
}]
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
f.node(&format!("request-{action}")).map(|n| &n.kind),
|
||||
Some(&NodeKind::RequestReviewer {
|
||||
reviewer: CLASSIFIER_ACCOUNT.to_owned()
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
f.children(&format!("match-{action}")),
|
||||
[format!("request-{action}")]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue