diff --git a/src/github.rs b/src/github.rs index d5307c9a1..b91a0e882 100644 --- a/src/github.rs +++ b/src/github.rs @@ -3,7 +3,6 @@ use tracing as log; use async_trait::async_trait; use chrono::{DateTime, FixedOffset, Utc}; -use futures::stream::{FuturesUnordered, StreamExt}; use futures::{future::BoxFuture, FutureExt}; use hyper::header::HeaderValue; use once_cell::sync::OnceCell; @@ -233,18 +232,6 @@ pub struct Label { pub name: String, } -impl Label { - async fn exists<'a>(&'a self, repo_api_prefix: &'a str, client: &'a GithubClient) -> bool { - #[allow(clippy::redundant_pattern_matching)] - let url = format!("{}/labels/{}", repo_api_prefix, self.name); - match client.send_req(client.get(&url)).await { - Ok(_) => true, - // XXX: Error handling if the request failed for reasons beyond 'label didn't exist' - Err(_) => false, - } - } -} - #[derive(Debug, serde::Deserialize)] pub struct PullRequestDetails { // none for now @@ -468,13 +455,40 @@ impl Issue { Ok(()) } - pub async fn set_labels( + pub async fn remove_label(&self, client: &GithubClient, label: &str) -> anyhow::Result<()> { + log::info!("remove_label from {}: {:?}", self.global_id(), label); + // DELETE /repos/:owner/:repo/issues/:number/labels/{name} + let url = format!( + "{repo_url}/issues/{number}/labels/{name}", + repo_url = self.repository().url(), + number = self.number, + name = label, + ); + + if !self.labels().iter().any(|l| l.name == label) { + log::info!( + "remove_label from {}: {:?} already not present, skipping", + self.global_id(), + label + ); + return Ok(()); + } + + client + ._send_req(client.delete(&url)) + .await + .context("failed to delete label")?; + + Ok(()) + } + + pub async fn add_labels( &self, client: &GithubClient, labels: Vec