manager: Remove Stale label if present

The stale label provides an easy way to force CI runs for issues after
changing dependencies.
This commit is contained in:
Rahix 2025-05-22 15:24:57 +02:00
parent e274f6206c
commit f04beb5dea
4 changed files with 49 additions and 0 deletions

View file

@ -1349,6 +1349,7 @@ dependencies = [
"serde",
"serde_json",
"sha256",
"time",
"tokio",
"url",
]

View file

@ -14,5 +14,6 @@ petgraph = "0.8.1"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
sha256 = "1.6.0"
time = "0.3.41"
tokio = { version = "1.45.0", features = ["full"] }
url = "2.5.4"

View file

@ -78,5 +78,42 @@ pub async fn update_bot_comment(
)
.await
.context("Failed to update comment body")?;
Ok(())
}
pub async fn remove_stale_label(
forgejo: &forgejo_api::Forgejo,
meta: &crate::event_meta::RepoMeta,
issue_number: u64,
) -> anyhow::Result<()> {
let labels = forgejo
.issue_get_labels(&meta.owner, &meta.name, issue_number)
.await
.context("Failed fetching issue labels")?;
let stale_label_id = labels
.iter()
.filter(|l| l.name.as_deref() == Some("Stale"))
.next()
.map(|l| l.id.unwrap());
if let Some(stale_label_id) = stale_label_id {
log::info!("Removing `Stale` label from issue #{issue_number}...");
forgejo
.issue_remove_label(
&meta.owner,
&meta.name,
issue_number,
stale_label_id,
forgejo_api::structs::DeleteLabelsOption {
updated_at: Some(time::OffsetDateTime::now_utc()),
},
)
.await
.context("Failed to remove the `Stale` label")?;
}
Ok(())
}

View file

@ -99,6 +99,12 @@ async fn run() -> anyhow::Result<()> {
if let Some(bot_comment) = bot_comment {
if bot_comment.body.contains(&hash) {
log::info!("Issue #{issue} is up-to-date, not editing comment.");
issue::remove_stale_label(&forgejo, &meta.issue.repository, issue)
.await
.with_context(|| {
format!("Failed to remove `Stale` label from issue #{issue}")
})?;
continue 'issues;
}
bot_comment.id
@ -128,6 +134,10 @@ async fn run() -> anyhow::Result<()> {
issue::update_bot_comment(&forgejo, &meta.issue.repository, comment_id, full_text)
.await
.with_context(|| format!("Failed to update the bot comment in issue #{issue}"))?;
issue::remove_stale_label(&forgejo, &meta.issue.repository, issue)
.await
.with_context(|| format!("Failed to remove `Stale` label from issue #{issue}"))?;
}
Ok(())