Better handling of id errors from issue API calls
All checks were successful
/ build (push) Successful in 1m7s

This commit is contained in:
Rahix 2025-12-09 16:19:21 +01:00
parent 83a610134c
commit c11026c5be

View file

@ -28,7 +28,7 @@ pub async fn make_bot_comment(
.await?; .await?;
Ok(BotCommentInfo { Ok(BotCommentInfo {
id: res.id.expect("TODO"), id: res.id.context("Missing id for the bot comment")?,
body: initial_message.to_owned(), body: initial_message.to_owned(),
}) })
} }
@ -55,12 +55,16 @@ pub async fn find_bot_comment(
let maybe_bot_comment = comments let maybe_bot_comment = comments
.iter() .iter()
.rev() .rev()
.find(|comment| comment.user.as_ref().expect("TODO").id == Some(-2)); .find(|comment| comment.user.as_ref().and_then(|u| u.id) == Some(-2));
Ok(maybe_bot_comment.map(|c| BotCommentInfo { Ok(maybe_bot_comment
.map(|c| -> anyhow::Result<_> {
Ok(BotCommentInfo {
body: c.body.clone().unwrap_or("".to_owned()), body: c.body.clone().unwrap_or("".to_owned()),
id: c.id.expect("TODO"), id: c.id.context("Missing id for the bot comment")?,
})) })
})
.transpose()?)
} }
/// Find existing bot comment or create a new one. /// Find existing bot comment or create a new one.
@ -155,7 +159,8 @@ pub async fn remove_stale_label(ctx: &crate::Context, issue_number: u64) -> anyh
.iter() .iter()
.filter(|l| l.name.as_deref() == Some("Stale")) .filter(|l| l.name.as_deref() == Some("Stale"))
.next() .next()
.map(|l| l.id.expect("TODO")); .map(|l| l.id.ok_or(anyhow::anyhow!("`Stale` label has no ID")))
.transpose()?;
if let Some(stale_label_id) = stale_label_id { if let Some(stale_label_id) = stale_label_id {
log::info!("Removing `Stale` label from issue #{issue_number}..."); log::info!("Removing `Stale` label from issue #{issue_number}...");