diff --git a/src/api/repos.rs b/src/api/repos.rs index d014c7c9..a2543651 100644 --- a/src/api/repos.rs +++ b/src/api/repos.rs @@ -6,6 +6,7 @@ use http::Uri; use snafu::ResultExt; mod branches; +mod collaborators; mod commits; pub mod events; mod file; @@ -18,10 +19,12 @@ mod secrets; mod stargazers; mod status; mod tags; +mod teams; use crate::error::HttpSnafu; use crate::{models, params, Octocrab, Result}; pub use branches::ListBranchesBuilder; +pub use collaborators::ListCollaboratorsBuilder; pub use commits::ListCommitsBuilder; pub use file::{DeleteFileBuilder, GetContentBuilder, UpdateFileBuilder}; pub use generate::GenerateRepositoryBuilder; @@ -32,6 +35,7 @@ pub use secrets::RepoSecretsHandler; pub use stargazers::ListStarGazersBuilder; pub use status::{CreateStatusBuilder, ListStatusesBuilder}; pub use tags::ListTagsBuilder; +pub use teams::ListTeamsBuilder; /// Handler for GitHub's repository API. /// @@ -381,6 +385,28 @@ impl<'octo> RepoHandler<'octo> { ListCommitsBuilder::new(self) } + /// List teams from a repository. + /// ```no_run + /// # async fn run() -> octocrab::Result<()> { + /// let teams = octocrab::instance().repos("owner", "repo").list_teams().send().await?; + /// # Ok(()) + /// # } + /// ``` + pub fn list_teams(&self) -> ListTeamsBuilder<'_, '_> { + ListTeamsBuilder::new(self) + } + + /// List collaborators from a repository. + /// ```no_run + /// # async fn run() -> octocrab::Result<()> { + /// let collaborators = octocrab::instance().repos("owner", "repo").list_collaborators().send().await?; + /// # Ok(()) + /// # } + /// ``` + pub fn list_collaborators(&self) -> ListCollaboratorsBuilder<'_, '_> { + ListCollaboratorsBuilder::new(self) + } + /// List star_gazers from a repository. /// ```no_run /// # async fn run() -> octocrab::Result<()> { diff --git a/src/api/repos/collaborators.rs b/src/api/repos/collaborators.rs new file mode 100644 index 00000000..9ed2a840 --- /dev/null +++ b/src/api/repos/collaborators.rs @@ -0,0 +1,43 @@ +use super::*; + +#[derive(serde::Serialize)] +pub struct ListCollaboratorsBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r RepoHandler<'octo>, + #[serde(skip_serializing_if = "Option::is_none")] + per_page: Option, + #[serde(skip_serializing_if = "Option::is_none")] + page: Option, +} + +impl<'octo, 'r> ListCollaboratorsBuilder<'octo, 'r> { + pub fn new(handler: &'r RepoHandler<'octo>) -> Self { + Self { + handler, + per_page: None, + page: None, + } + } + + /// Results per page (max 100). + pub fn per_page(mut self, per_page: impl Into) -> Self { + self.per_page = Some(per_page.into()); + self + } + + /// Page number of the results to fetch. + pub fn page(mut self, page: impl Into) -> Self { + self.page = Some(page.into()); + self + } + + /// Sends the actual request. + pub async fn send(self) -> crate::Result> { + let route = format!( + "/repos/{owner}/{repo}/collaborators", + owner = self.handler.owner, + repo = self.handler.repo + ); + self.handler.crab.get(route, Some(&self)).await + } +} diff --git a/src/api/repos/teams.rs b/src/api/repos/teams.rs new file mode 100644 index 00000000..6902ec79 --- /dev/null +++ b/src/api/repos/teams.rs @@ -0,0 +1,43 @@ +use super::*; + +#[derive(serde::Serialize)] +pub struct ListTeamsBuilder<'octo, 'r> { + #[serde(skip)] + handler: &'r RepoHandler<'octo>, + #[serde(skip_serializing_if = "Option::is_none")] + per_page: Option, + #[serde(skip_serializing_if = "Option::is_none")] + page: Option, +} + +impl<'octo, 'r> ListTeamsBuilder<'octo, 'r> { + pub fn new(handler: &'r RepoHandler<'octo>) -> Self { + Self { + handler, + per_page: None, + page: None, + } + } + + /// Results per page (max 100). + pub fn per_page(mut self, per_page: impl Into) -> Self { + self.per_page = Some(per_page.into()); + self + } + + /// Page number of the results to fetch. + pub fn page(mut self, page: impl Into) -> Self { + self.page = Some(page.into()); + self + } + + /// Sends the actual request. + pub async fn send(self) -> crate::Result> { + let route = format!( + "/repos/{owner}/{repo}/teams", + owner = self.handler.owner, + repo = self.handler.repo + ); + self.handler.crab.get(route, Some(&self)).await + } +} diff --git a/src/models.rs b/src/models.rs index 4ad55da5..798a1de3 100644 --- a/src/models.rs +++ b/src/models.rs @@ -403,6 +403,14 @@ pub struct Author { pub site_admin: bool, } +#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] +#[non_exhaustive] +pub struct Collaborator { + #[serde(flatten)] + pub author: Author, + pub permissions: Permissions, +} + #[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] #[non_exhaustive] pub struct StarGazer {