pub fn trailers(text: &str) -> Vec<(String, String)>Expand description
The trailers of a message: the lines Key: value of its last block of
trailers. The block is the last paragraphs of the message that hold
only such lines. GitHub adds its Co-authored-by: lines after a blank
line, so the block may have more than one paragraph. A paragraph with a
line of another form ends the block, and a last paragraph of that form
leaves no trailer at all.
let body = "Closes #7\n\nText.\n\nIssue: #7\nMilestone: Wave 3\n";
assert_eq!(hygiene::trailers(body), [
("Issue".to_owned(), "#7".to_owned()),
("Milestone".to_owned(), "Wave 3".to_owned()),
]);
assert!(hygiene::trailers("Text.\n\nIssue: #7\nmore text").is_empty());
// The squash of a pull request with a co-author:
let squash = "Text.\n\nIssue: #7\nMilestone: Wave 3\n\nCo-authored-by: A <a@b.c>\n";
let keys: Vec<_> = hygiene::trailers(squash).into_iter().map(|(k, _)| k).collect();
assert_eq!(keys, ["Issue", "Milestone", "Co-authored-by"]);
// A paragraph of text after the trailers ends the block.
assert!(hygiene::trailers("Issue: #7\n\nText.\n\nCo-authored-by: A <a@b.c>\n")
.iter()
.all(|(k, _)| k != "Issue"));