manager: Add first version of the techtree manager

The techtree manager is a CI tool that derives the techtree graph from
the forgejo issues in this repository.  It then adds graph
visualizations to each issue and the wiki, to give an overview of the
tree.
This commit is contained in:
Rahix 2025-05-22 09:48:01 +02:00
parent 8ab73f4a4a
commit 870e54e263
9 changed files with 2768 additions and 0 deletions

View file

@ -0,0 +1,82 @@
use anyhow::Context as _;
pub type CommentId = u64;
pub struct BotCommentInfo {
pub body: String,
pub id: CommentId,
}
pub async fn make_bot_comment(
forgejo: &forgejo_api::Forgejo,
meta: &crate::event_meta::IssueEventMeta,
issue_number: u64,
) -> anyhow::Result<CommentId> {
let initial_message =
"_Please be patient, this issue is currently being integrated into the techtree..._";
let res = forgejo
.issue_create_comment(
&meta.issue.repository.owner,
&meta.issue.repository.name,
issue_number,
forgejo_api::structs::CreateIssueCommentOption {
body: initial_message.to_owned(),
updated_at: None,
},
)
.await?;
Ok(res.id.unwrap())
}
pub async fn find_bot_comment(
forgejo: &forgejo_api::Forgejo,
meta: &crate::event_meta::RepoMeta,
issue_number: u64,
) -> anyhow::Result<Option<BotCommentInfo>> {
let mut comments = forgejo
.issue_get_comments(
&meta.owner,
&meta.name,
issue_number,
forgejo_api::structs::IssueGetCommentsQuery {
..Default::default()
},
)
.await
.context("Failed fetching comments for issue")?;
comments.sort_by_key(|comment| comment.created_at);
let maybe_bot_comment = comments
.iter()
.rev()
.find(|comment| comment.user.as_ref().unwrap().id == Some(-2));
Ok(maybe_bot_comment.map(|c| BotCommentInfo {
body: c.body.clone().unwrap_or("".to_owned()),
id: c.id.unwrap(),
}))
}
pub async fn update_bot_comment(
forgejo: &forgejo_api::Forgejo,
meta: &crate::event_meta::RepoMeta,
id: CommentId,
new_body: String,
) -> anyhow::Result<()> {
forgejo
.issue_edit_comment(
&meta.owner,
&meta.name,
id,
forgejo_api::structs::EditIssueCommentOption {
body: new_body,
updated_at: None,
},
)
.await
.context("Failed to update comment body")?;
Ok(())
}