Fix clippy lints

This commit is contained in:
Rahix 2025-12-09 16:48:42 +01:00
parent c11026c5be
commit be7f305a6b
6 changed files with 23 additions and 23 deletions

View file

@ -24,7 +24,7 @@ pub async fn collect_tree(ctx: &crate::Context) -> anyhow::Result<crate::tree::T
.await
.with_context(|| format!("Failed fetching page {page} of the issue list"))?;
if new.len() == 0 {
if new.is_empty() {
break;
}
@ -84,7 +84,7 @@ pub async fn collect_tree(ctx: &crate::Context) -> anyhow::Result<crate::tree::T
}
let dep_number = dep.number.context("Missing issue number in dependency")?;
if !tree.find_element_by_issue_number(dep_number).is_some() {
if tree.find_element_by_issue_number(dep_number).is_none() {
log::warn!("Found dependency from #{issue} on non-tracked issue #{dep_number}!");
} else {
tree.add_dependency_by_issue_number(issue, dep_number);
@ -133,11 +133,7 @@ fn element_from_issue(issue: &forgejo_api::structs::Issue) -> anyhow::Result<cra
if has_completed_label {
crate::tree::ElementStatus::Completed
} else if issue.assignee.is_some()
|| issue
.assignees
.as_ref()
.map(|v| v.len() > 0)
.unwrap_or(false)
|| issue.assignees.as_ref().is_some_and(|v| !v.is_empty())
{
crate::tree::ElementStatus::Assigned
} else {

View file

@ -57,14 +57,14 @@ pub async fn find_bot_comment(
.rev()
.find(|comment| comment.user.as_ref().and_then(|u| u.id) == Some(-2));
Ok(maybe_bot_comment
maybe_bot_comment
.map(|c| -> anyhow::Result<_> {
Ok(BotCommentInfo {
body: c.body.clone().unwrap_or("".to_owned()),
id: c.id.context("Missing id for the bot comment")?,
})
})
.transpose()?)
.transpose()
}
/// Find existing bot comment or create a new one.
@ -115,12 +115,12 @@ pub async fn update_bot_comment_from_subtree(
subtree: &crate::tree::Subtree<'_>,
hash: &str,
) -> anyhow::Result<()> {
let mut mermaid = subtree.to_mermaid(&ctx.repo_url.to_string(), false);
let mut mermaid = subtree.to_mermaid(ctx.repo_url.as_ref(), false);
// 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);
mermaid = subtree.to_mermaid(ctx.repo_url.as_ref(), true);
}
let full_text = if mermaid.len() > 4990 {
@ -143,7 +143,7 @@ _Sorry, the partial techtree is still too big to be displayed for this element..
)
};
update_bot_comment(&ctx, id, full_text).await?;
update_bot_comment(ctx, id, full_text).await?;
Ok(())
}
@ -157,8 +157,7 @@ pub async fn remove_stale_label(ctx: &crate::Context, issue_number: u64) -> anyh
let stale_label_id = labels
.iter()
.filter(|l| l.name.as_deref() == Some("Stale"))
.next()
.find(|l| l.name.as_deref() == Some("Stale"))
.map(|l| l.id.ok_or(anyhow::anyhow!("`Stale` label has no ID")))
.transpose()?;

View file

@ -1,4 +1,7 @@
#![allow(dead_code)]
#![allow(clippy::useless_format)]
#![allow(clippy::needless_return)]
#![deny(clippy::as_conversions)]
use anyhow::Context as _;
use forgejo_api::Forgejo;
@ -69,7 +72,7 @@ async fn run() -> anyhow::Result<()> {
.map(|token| -> Result<_, ()> {
let mut repo_auth_url = repo_url.clone();
repo_auth_url.set_username("forgejo-actions")?;
repo_auth_url.set_password(Some(&token))?;
repo_auth_url.set_password(Some(token))?;
Ok(repo_auth_url)
})
.transpose()
@ -145,7 +148,9 @@ async fn run() -> anyhow::Result<()> {
}
'issues: for issue in tree.iter_issues() {
let subtree = tree.subtree_for_issue(issue).expect("issue from tree not found in tree");
let subtree = tree
.subtree_for_issue(issue)
.expect("issue from tree not found in tree");
let hash = subtree.stable_hash();
let (bot_comment, _is_new) = issue::find_or_make_bot_comment(&ctx, issue)

View file

@ -52,14 +52,14 @@ pub async fn render(
std::fs::create_dir(&info.repo_dir).context("Failed creating directory for rendered graph")?;
let dot_source = tree.to_dot();
std::fs::write(&info.dot_file(), dot_source.as_bytes())
std::fs::write(info.dot_file(), dot_source.as_bytes())
.context("Failed to write `dot` source file")?;
Command::new("dot")
.args(["-T", "svg"])
.arg("-o")
.arg(&info.svg_file())
.arg(&info.dot_file())
.arg(info.svg_file())
.arg(info.dot_file())
.success()
.context("Failed to generate svg graph from dot source")?;

View file

@ -263,7 +263,7 @@ impl Tree {
for index in self.graph.node_indices() {
mermaid.push_str(&self.graph[index].to_mermaid_node(index, None, repo_url, simple));
mermaid.push_str("\n");
mermaid.push('\n');
}
for edge in self.graph.edge_references() {
@ -397,7 +397,7 @@ impl<'a> Subtree<'a> {
repo_url,
simple,
));
mermaid.push_str("\n");
mermaid.push('\n');
}
for edge in self.graph.edge_references() {

View file

@ -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(), false);
let mermaid = tree.to_mermaid(ctx.repo_url.as_ref(), false);
let wiki_text = format!(
r##"This page is automatically updated to show the latest and greatest FAFO techtree:
@ -14,7 +14,7 @@ pub async fn update_wiki_from_tree(
```
"##
);
update_wiki_overview(&ctx, wiki_text)
update_wiki_overview(ctx, wiki_text)
.await
.context("Failed to update the techtree wiki page")?;
Ok(())