From 24e834dde3aed34af3c6364146ed8a0b5b11a49c Mon Sep 17 00:00:00 2001 From: Rahix Date: Thu, 22 May 2025 15:40:18 +0200 Subject: [PATCH] manager: Don't hardcode repository URL --- techtree-manager/src/main.rs | 7 ++++--- techtree-manager/src/tree.rs | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/techtree-manager/src/main.rs b/techtree-manager/src/main.rs index ed5678f..6be028c 100644 --- a/techtree-manager/src/main.rs +++ b/techtree-manager/src/main.rs @@ -34,12 +34,13 @@ async fn run() -> anyhow::Result<()> { ) .context("Failed parsing GITHUB_SERVER_URL as a url")?; - let mut repo_auth_url = server_url + let repo_url = server_url .join(&format!( "{}/{}", meta.issue.repository.owner, meta.issue.repository.name )) .unwrap(); + let mut repo_auth_url = repo_url.clone(); repo_auth_url.set_username("forgejo-actions").unwrap(); repo_auth_url.set_password(Some(&token)).unwrap(); @@ -71,7 +72,7 @@ async fn run() -> anyhow::Result<()> { .await .context("Failed to render and publish the techtree to git")?; - let mermaid = tree.to_mermaid(); + let mermaid = tree.to_mermaid(&repo_url.to_string()); let wiki_text = format!( r##"This page is automatically updated to show the latest and greatest FAFO techtree: @@ -124,7 +125,7 @@ async fn run() -> anyhow::Result<()> { } }; - let mermaid = subtree.to_mermaid(); + let mermaid = subtree.to_mermaid(&repo_url.to_string()); let full_text = format!( r##"## Partial Techtree diff --git a/techtree-manager/src/tree.rs b/techtree-manager/src/tree.rs index 58e8fe1..6bb5217 100644 --- a/techtree-manager/src/tree.rs +++ b/techtree-manager/src/tree.rs @@ -46,7 +46,12 @@ impl Element { attributes.join(", ") } - fn to_mermaid_node(&self, index: ElementIndex, role: Option) -> String { + fn to_mermaid_node( + &self, + index: ElementIndex, + role: Option, + repo_url: &str, + ) -> String { let Element { issue_number, description, @@ -55,7 +60,7 @@ impl Element { } = self; let label = format!( - r##"#{issue_number} | {status}\n{ty}\n{description}"## + r##"#{issue_number} | {status}\n{ty}\n{description}"## ); let class = match (role, status) { @@ -163,13 +168,13 @@ impl Tree { format!("{:?}", dot) } - pub fn to_mermaid(&self) -> String { + pub fn to_mermaid(&self, repo_url: &str) -> 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)); + mermaid.push_str(&self.graph[index].to_mermaid_node(index, None, repo_url)); mermaid.push_str("\n"); } @@ -287,14 +292,18 @@ impl<'a> Subtree<'a> { format!("{:?}", dot) } - pub fn to_mermaid(&self) -> String { + pub fn to_mermaid(&self, repo_url: &str) -> 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))); + mermaid.push_str( + &node + .element + .to_mermaid_node(index, Some(node.role), repo_url), + ); mermaid.push_str("\n"); }