gitee_cli_rs/api/
collaborators.rs1use super::client::Client;
2use crate::error::Result;
3use crate::models::Collaborator;
4use crate::repo::Repo;
5
6pub struct Collaborators<'a> {
7 client: &'a Client,
8 repo: &'a Repo,
9}
10
11impl Collaborators<'_> {
12 pub(crate) fn new<'a>(client: &'a Client, repo: &'a Repo) -> Collaborators<'a> {
13 Collaborators { client, repo }
14 }
15
16 pub fn list(&self, limit: usize) -> Result<Vec<Collaborator>> {
17 let (o, r) = (&self.repo.owner, &self.repo.name);
18 self.client
19 .get_paged(&format!("/repos/{o}/{r}/collaborators"), &[], limit)
20 }
21
22 pub fn add(&self, username: &str, permission: &str) -> Result<()> {
24 let (o, r) = (&self.repo.owner, &self.repo.name);
25 self.client.put_ok(
26 &format!("/repos/{o}/{r}/collaborators/{username}"),
27 &[("permission", permission)],
28 )
29 }
30
31 pub fn remove(&self, username: &str) -> Result<()> {
32 let (o, r) = (&self.repo.owner, &self.repo.name);
33 self.client
34 .delete_ok(&format!("/repos/{o}/{r}/collaborators/{username}"))
35 }
36}