manager: Simplify very complex mermaid graphs
All checks were successful
/ build (push) Successful in 1m4s
All checks were successful
/ build (push) Successful in 1m4s
Forgejo has a limit of 5000 characters per mermaid graph. We started hitting this for some issues. Regenerate a somewhat simplified version of the subtree in this case which hopefully does not hit the same limit again.
This commit is contained in:
parent
42ec50cb64
commit
cc05ba7407
|
@ -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..._
|
||||
|
||||
<small>Digest: {hash}; Last Updated: {timestamp}</small>"##,
|
||||
timestamp = ctx.timestamp,
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
r##"## Partial Techtree
|
||||
```mermaid
|
||||
{mermaid}
|
||||
```
|
||||
|
||||
<small>Digest: {hash}; Last Updated: {timestamp}</small>"##,
|
||||
timestamp = ctx.timestamp,
|
||||
);
|
||||
timestamp = ctx.timestamp,
|
||||
)
|
||||
};
|
||||
|
||||
update_bot_comment(&ctx, id, full_text).await?;
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ impl Element {
|
|||
index: ElementIndex,
|
||||
role: Option<SubtreeElementRole>,
|
||||
repo_url: &str,
|
||||
simple: bool,
|
||||
) -> String {
|
||||
let Element {
|
||||
issue_number,
|
||||
|
@ -59,9 +60,13 @@ impl Element {
|
|||
status,
|
||||
} = self;
|
||||
|
||||
let label = format!(
|
||||
r##"<a href='{repo_url}/issues/{issue_number}' target='_blank'>#{issue_number}</a> | {status}\n<i>{ty}</i>\n<b>{description}</b>"##
|
||||
);
|
||||
let label = if simple {
|
||||
format!(r##"#{issue_number} | {status}\n<i>{ty}</i>\n<b>{description}</b>"##)
|
||||
} else {
|
||||
format!(
|
||||
r##"<a href='{repo_url}/issues/{issue_number}' target='_blank'>#{issue_number}</a> | {status}\n<i>{ty}</i>\n<b>{description}</b>"##
|
||||
)
|
||||
};
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in a new issue