grp_core/common/repos/
urls.rs1use crate::common::users::structs::UserType;
2use crate::platform::Platform;
3
4
5impl Platform {
6 pub(crate) async fn url_list_repos<S: AsRef<str>>(&self, user_type: &UserType, endpoint: &S) -> String {
7 match (user_type, self) {
8 (UserType::LoggedUser(_), Platform::Gitea) |
9 (UserType::LoggedUser(_), Platform::Codeberg) |
10 (UserType::LoggedUser(_), Platform::Forgejo) |
11 (UserType::LoggedUser(_), Platform::Github) => {
12 format!("{}/user/repos", self.get_base_url(endpoint))
13 }
14 (UserType::LoggedOrg(user), Platform::Gitea) |
15 (UserType::LoggedOrg(user), Platform::Codeberg) |
16 (UserType::LoggedOrg(user), Platform::Forgejo) |
17 (UserType::LoggedOrg(user), Platform::Github) => {
18 format!("{}/orgs/{}/repos", self.get_base_url(endpoint), user.name)
19 }
20 (UserType::UnloggedUser(user), Platform::Gitea) |
21 (UserType::UnloggedUser(user), Platform::Codeberg) |
22 (UserType::UnloggedUser(user), Platform::Forgejo) |
23 (UserType::UnloggedUser(user), Platform::Github) => {
24 format!("{}/users/{}/repos", self.get_base_url(endpoint), user.name)
25 }
26 (UserType::LoggedUser(_), Platform::Gitlab) => {
27 format!("{}/projects?membership=true", self.get_base_url(endpoint))
28 }
29 (UserType::LoggedOrg(u), Platform::Gitlab) |
30 (UserType::UnloggedOrg(u), Platform::Gitlab) => {
31 format!("{}/groups/{}/projects", self.get_base_url(endpoint), u.id)
32 }
33 (UserType::UnloggedUser(u), Platform::Gitlab) => {
34 format!("{}/users/{}/projects", self.get_base_url(endpoint), u.id)
35 }
36 _ => todo!("Not implemented")
37 }
38 }
39
40 pub(crate) async fn url_create_repo<S: AsRef<str>>(&self, user_type: &UserType, endpoint: &S) -> String {
41 match (user_type, self) {
42 (UserType::LoggedUser(_), Platform::Gitea) |
43 (UserType::LoggedUser(_), Platform::Codeberg) |
44 (UserType::LoggedUser(_), Platform::Forgejo) |
45 (UserType::LoggedUser(_), Platform::Github) => {
46 format!("{}/user/repos", self.get_base_url(endpoint))
47 }
48 (UserType::LoggedOrg(user), Platform::Gitea) |
49 (UserType::LoggedOrg(user), Platform::Codeberg) |
50 (UserType::LoggedOrg(user), Platform::Forgejo) |
51 (UserType::LoggedOrg(user), Platform::Github) => {
52 format!("{}/orgs/{}/repos", self.get_base_url(endpoint), user.name)
53 }
54 (UserType::UnloggedUser(user), Platform::Gitea) |
55 (UserType::UnloggedUser(user), Platform::Codeberg) |
56 (UserType::UnloggedUser(user), Platform::Forgejo) |
57 (UserType::UnloggedUser(user), Platform::Github) => {
58 format!("{}/users/{}/repos", self.get_base_url(endpoint), user.name)
59 }
60 (utype, Platform::Gitlab) => {
61 let u = utype.get_user();
62 format!("{}/projects?namespace_id={}", self.get_base_url(endpoint), u.id)
63 }
64 _ => todo!("Not implemented")
65 }
66 }
67
68 pub async fn url_delete_repo<S: AsRef<str>>(&self, owner: &S, repo: &S, endpoint: &S) -> String {
69 match self {
70 Platform::Github |
71 Platform::Codeberg |
72 Platform::Forgejo |
73 Platform::Gitea => format!("{}/repos/{}/{}", self.get_base_url(endpoint), owner.as_ref(), repo.as_ref()),
74 Platform::Gitlab => {
75 format!("{}/projects/{}", self.get_base_url(endpoint), owner.as_ref())
76 },
77 }
78 }
79
80
81}