grp_core/common/orgs/
delete.rs1use crate::platform::Platform;
2use crate::error::structs::Error;
3use crate::config::Config;
4use crate::common::structs::{Context, RequestType};
5use crate::animation::Animation;
6use crate::specific::gitlab;
7
8
9impl Platform {
10 pub async fn delete_org<T: Into<String>, A: Animation + ?Sized>(&self,
23 name: T,
24 config: &Config,
25 permanent: bool,
26 animation: &Box<A>
27 ) -> Result<(), Error> {
28 let mut name = name.into();
29 let name_copy = name.clone();
30
31 if matches!(self, Platform::Gitlab) {
32 animation.change_message("getting group id");
33 let user = gitlab::groups::get::get_group_with_path(self, &name, config).await?;
34 name = user.id;
35 }
36
37 animation.change_message("generating url ...");
38 let url = self.url_delete_org(&name, &config.endpoint);
39
40 animation.change_message("Deleting organization ...");
41 let result = self.delete(&url, config).await?;
42
43 match (self, result.status().as_u16()) {
44 (Platform::Gitlab, 202 | 400) if permanent => {
45 animation.change_message("Permamently deleting gitlab group ...");
46 let user = gitlab::groups::get::get_group_by_id(self, &name, config).await?;
47 let _ = gitlab::groups::delete::premanently_remove(&self, &user, config).await?;
48 Ok(())
49 },
50 (
51 Platform::Codeberg |
52 Platform::Forgejo
53 , 204
54 ) | (_, 202) => Ok(()),
55 (_, _) => {
56 let context = Context {
57 request_type: RequestType::DeleteOrg,
58 owner: Some(name_copy),
59 repo: None,
60 additional: None
61 };
62
63 let base_message = "Error deleting organization";
64 Err(self.unwrap(result, base_message, &config, context).await.unwrap_err())
65 }
66 }
67 }
68}