summaryrefslogtreecommitdiff
path: root/server/common
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-02-06 00:05:57 +0100
committerJoel Klinghed <the_jk@spawned.biz>2025-02-06 00:05:57 +0100
commitbd74717e10fb36e19893c15941876b2383b94714 (patch)
tree5fc26ace64c37fb439ba94cc5ea437a0e93913d2 /server/common
parent350fc534de745f4cc62000fa25d67afcddb7918a (diff)
Add DELETE command for review
Only the owner or a maintainer of the project can remove a review. Removing a review also removes the git branch. Only reviews that are either draft or dropped can be removed.
Diffstat (limited to 'server/common')
-rw-r--r--server/common/src/git.rs13
-rw-r--r--server/common/src/tests.rs19
2 files changed, 31 insertions, 1 deletions
diff --git a/server/common/src/git.rs b/server/common/src/git.rs
index 74c3247..ac0bdb3 100644
--- a/server/common/src/git.rs
+++ b/server/common/src/git.rs
@@ -326,6 +326,12 @@ impl RepoData {
.await
}
+ async fn delete_branch(&self, repo: &Repository, branch: &str) -> Result<(), Error> {
+ let mut cmd = self.git_cmd(repo);
+ cmd.arg("branch").arg("--delete").arg("--force").arg(branch);
+ self.run(&mut cmd).await
+ }
+
async fn get_log_format(
&self,
repo: &Repository,
@@ -564,4 +570,11 @@ impl Repository {
data.get_commiter(self, commit.as_str()).await
}
+
+ pub async fn delete_branch(&self, branch: impl Into<String>) -> Result<(), Error> {
+ let branch = branch.into();
+ let data = self.lock.read().await;
+
+ data.delete_branch(self, branch.as_str()).await
+ }
}
diff --git a/server/common/src/tests.rs b/server/common/src/tests.rs
index f08ca44..41f44fe 100644
--- a/server/common/src/tests.rs
+++ b/server/common/src/tests.rs
@@ -202,7 +202,7 @@ async fn git_get_author_commiter(repo: &git::Repository) {
assert!(repo.get_author("<invalid>").await.is_err());
}
-async fn git_fetch(bare: bool) {
+async fn git_fetch(bare: bool) -> git::Repository {
let path = testdir!().join("repo");
let remote_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/testdata/bare");
let remote = remote_path.to_string_lossy().into_owned();
@@ -231,6 +231,7 @@ async fn git_fetch(bare: bool) {
branch.unwrap();
other.unwrap();
}
+ repo
}
#[tokio::test]
@@ -266,3 +267,19 @@ async fn test_git_fetch() {
async fn test_git_bare_fetch() {
git_fetch(true).await;
}
+
+#[tokio::test]
+async fn test_git_delete_branch() {
+ // Using git_fetch as we need a writeable git repo
+ let repo = git_fetch(false).await;
+ assert!(repo.delete_branch("other").await.is_ok());
+ assert!(repo.delete_branch("does-not-exist").await.is_err());
+}
+
+#[tokio::test]
+async fn test_git_bare_delete_branch() {
+ // Using git_fetch as we need a writeable git repo
+ let repo = git_fetch(true).await;
+ assert!(repo.delete_branch("other").await.is_ok());
+ assert!(repo.delete_branch("does-not-exist").await.is_err());
+}