diff --git a/techtree-manager/src/issue.rs b/techtree-manager/src/issue.rs index 3fd50c7..510a03b 100644 --- a/techtree-manager/src/issue.rs +++ b/techtree-manager/src/issue.rs @@ -111,17 +111,33 @@ pub async fn update_bot_comment_from_subtree( subtree: &crate::tree::Subtree<'_>, hash: &str, ) -> anyhow::Result<()> { - let mermaid = subtree.to_mermaid(&ctx.repo_url.to_string()); + let mut mermaid = subtree.to_mermaid(&ctx.repo_url.to_string(), false); - let full_text = format!( - r##"## Partial Techtree + // When the mermaid graph gets too big, regenerate a simplified version. + if mermaid.len() > 4990 { + log::info!("Mermaid graph is too big, generating simplified version..."); + mermaid = subtree.to_mermaid(&ctx.repo_url.to_string(), true); + } + + let full_text = if mermaid.len() > 4990 { + format!( + r##"## Partial Techtree +_Sorry, the partial techtree is still too big to be displayed for this element..._ + +Digest: {hash}; Last Updated: {timestamp}"##, + timestamp = ctx.timestamp, + ) + } else { + format!( + r##"## Partial Techtree ```mermaid {mermaid} ``` Digest: {hash}; Last Updated: {timestamp}"##, - timestamp = ctx.timestamp, - ); + timestamp = ctx.timestamp, + ) + }; update_bot_comment(&ctx, id, full_text).await?; diff --git a/techtree-manager/src/tree.rs b/techtree-manager/src/tree.rs index dae74f2..207515c 100644 --- a/techtree-manager/src/tree.rs +++ b/techtree-manager/src/tree.rs @@ -51,6 +51,7 @@ impl Element { index: ElementIndex, role: Option, repo_url: &str, + simple: bool, ) -> String { let Element { issue_number, @@ -59,9 +60,13 @@ impl Element { status, } = self; - let label = format!( - r##"#{issue_number} | {status}\n{ty}\n{description}"## - ); + let label = if simple { + format!(r##"#{issue_number} | {status}\n{ty}\n{description}"##) + } else { + format!( + r##"#{issue_number} | {status}\n{ty}\n{description}"## + ) + }; let class = match (role, status) { (Some(SubtreeElementRole::ElementOfInterest), _) => "eoi", @@ -176,13 +181,13 @@ impl Tree { ) } - pub fn to_mermaid(&self, repo_url: &str) -> String { + pub fn to_mermaid(&self, repo_url: &str, simple: bool) -> String { let mut mermaid = String::new(); mermaid.push_str("flowchart BT\n"); mermaid.push_str(&mermaid_classes()); for index in self.graph.node_indices() { - mermaid.push_str(&self.graph[index].to_mermaid_node(index, None, repo_url)); + mermaid.push_str(&self.graph[index].to_mermaid_node(index, None, repo_url, simple)); mermaid.push_str("\n"); } @@ -300,18 +305,19 @@ impl<'a> Subtree<'a> { format!("{:?}", dot) } - pub fn to_mermaid(&self, repo_url: &str) -> String { + pub fn to_mermaid(&self, repo_url: &str, simple: bool) -> String { let mut mermaid = String::new(); mermaid.push_str("flowchart BT\n"); mermaid.push_str(&mermaid_classes()); for index in self.graph.node_indices() { let node = &self.graph[index]; - mermaid.push_str( - &node - .element - .to_mermaid_node(index, Some(node.role), repo_url), - ); + mermaid.push_str(&node.element.to_mermaid_node( + index, + Some(node.role), + repo_url, + simple, + )); mermaid.push_str("\n"); } diff --git a/techtree-manager/src/wiki.rs b/techtree-manager/src/wiki.rs index 9c48ee6..e61f931 100644 --- a/techtree-manager/src/wiki.rs +++ b/techtree-manager/src/wiki.rs @@ -5,7 +5,7 @@ pub async fn update_wiki_from_tree( ctx: &crate::Context, tree: &crate::tree::Tree, ) -> anyhow::Result<()> { - let mermaid = tree.to_mermaid(&ctx.repo_url.to_string()); + let mermaid = tree.to_mermaid(&ctx.repo_url.to_string(), false); let wiki_text = format!( r##"This page is automatically updated to show the latest and greatest FAFO techtree: