1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use regex::Regex;
use crate::api::search::PullRequestStatus;
use crate::graph::FlatDep;
fn process(row: String) -> String {
let regex = Regex::new(r"\[HEAP-\d+\]\s*").unwrap();
regex.replace_all(&row, "").into_owned()
}
pub fn build_table(deps: FlatDep, title: &str) -> String {
let is_complete = deps
.iter()
.all(|(node, _)| node.state() == &PullRequestStatus::Closed);
let mut out = String::new();
if is_complete {
out.push_str(&format!("### ✅ Stacked PR Chain: {}\n", title));
} else {
out.push_str(&format!("### Stacked PR Chain: {}\n", title));
}
out.push_str("| PR | Title | Merges Into |\n");
out.push_str("|:--:|:------|:-------------:|\n");
for (node, parent) in deps {
let row = match parent {
Some(parent) => format!(
"|#{}|{}|#{}|\n",
node.number(),
node.title(),
parent.number()
),
None => format!(
"|#{}|{}|**{}**|\n",
node.number(),
node.title(),
node.note()
),
};
out.push_str(&process(row));
}
out
}