From 31f5aabc7ca679c15d224552afb65b8655938e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 9 Feb 2024 14:18:59 +0000 Subject: [PATCH] Add delete_ref in RepoHandler Fixes: https://github.com/XAMPPRocky/octocrab/issues/572 --- src/api/repos.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/api/repos.rs b/src/api/repos.rs index 065ed0ec..6e169f03 100644 --- a/src/api/repos.rs +++ b/src/api/repos.rs @@ -210,6 +210,32 @@ impl<'octo> RepoHandler<'octo> { .await } + /// Deletes an existing reference from the repository. + /// ```no_run + /// # async fn run() -> octocrab::Result<()> { + /// # let master_sha = ""; + /// use octocrab::params::repos::Reference; + /// + /// // Deletes the "heads/temporary-branch" reference. + /// octocrab::instance() + /// .repos("owner", "repo") + /// .delete_ref(&Reference::Branch("temporary-branch".to_string())) + /// .await?; + /// # Ok(()) + /// # } + /// ``` + pub async fn delete_ref(&self, reference: ¶ms::repos::Reference) -> Result<()> { + let route = format!( + "/repos/{owner}/{repo}/git/refs/{ref}", + owner = self.owner, + repo = self.repo, + ref = reference.ref_url() + ); + crate::map_github_error(self.crab._delete(route, None::<&()>).await?) + .await + .map(drop) + } + /// Get repository content. /// ```no_run /// # async fn run() -> octocrab::Result<()> {