manager: Don't hardcode repository URL

This commit is contained in:
Rahix 2025-05-22 15:40:18 +02:00
parent d0c8389c3b
commit 24e834dde3
2 changed files with 19 additions and 9 deletions

View file

@ -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

View file

@ -46,7 +46,12 @@ impl Element {
attributes.join(", ")
}
fn to_mermaid_node(&self, index: ElementIndex, role: Option<SubtreeElementRole>) -> String {
fn to_mermaid_node(
&self,
index: ElementIndex,
role: Option<SubtreeElementRole>,
repo_url: &str,
) -> String {
let Element {
issue_number,
description,
@ -55,7 +60,7 @@ impl Element {
} = self;
let label = format!(
r##"<a href='/rahix/techtree-poc/issues/{issue_number}' target='_blank'>#{issue_number}</a> | {status}\n<i>{ty}</i>\n<b>{description}</b>"##
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) {
@ -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");
}