diff --git a/examples/create_repo_from_template.rs b/examples/create_repo_from_template.rs index c58f9e61..038c330c 100644 --- a/examples/create_repo_from_template.rs +++ b/examples/create_repo_from_template.rs @@ -4,7 +4,9 @@ use octocrab::Octocrab; async fn main() -> octocrab::Result<()> { let token = std::env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN env variable is required"); - let octocrab = Octocrab::builder().personal_token(token.to_string()).build()?; + let octocrab = Octocrab::builder() + .personal_token(token.to_string()) + .build()?; let repository = octocrab.repos("rust-lang", "rust-template"); repository @@ -17,4 +19,4 @@ async fn main() -> octocrab::Result<()> { .await?; Ok(()) -} \ No newline at end of file +} diff --git a/examples/get_repo.rs b/examples/get_repo.rs index 592783bc..6adc4353 100644 --- a/examples/get_repo.rs +++ b/examples/get_repo.rs @@ -8,7 +8,10 @@ async fn main() -> octocrab::Result<()> { let repo = octocrab.repos("rust-lang", "rust").get().await?; - let repo_metrics = octocrab.repos("rust-lang", "rust").get_community_profile_metrics().await?; + let repo_metrics = octocrab + .repos("rust-lang", "rust") + .get_community_profile_metrics() + .await?; println!( "{} has {} stars and {}% health percentage", diff --git a/examples/github_app_authentication_manual.rs b/examples/github_app_authentication_manual.rs index ab049409..f53b117d 100644 --- a/examples/github_app_authentication_manual.rs +++ b/examples/github_app_authentication_manual.rs @@ -1,4 +1,4 @@ -use octocrab::models::{InstallationToken, InstallationRepositories}; +use octocrab::models::{InstallationRepositories, InstallationToken}; use octocrab::params::apps::CreateInstallationAccessToken; use octocrab::Octocrab; diff --git a/examples/is_collab.rs b/examples/is_collab.rs index cd1de221..9109225d 100644 --- a/examples/is_collab.rs +++ b/examples/is_collab.rs @@ -6,7 +6,10 @@ async fn main() -> octocrab::Result<()> { let octocrab = Octocrab::builder().personal_token(token).build()?; - let repo = octocrab.repos("rust-lang", "rust").is_collaborator("Roger-luo").await?; + let repo = octocrab + .repos("rust-lang", "rust") + .is_collaborator("Roger-luo") + .await?; if repo { println!("Roger-luo is a collaborator of rust-lang/rust"); @@ -15,4 +18,4 @@ async fn main() -> octocrab::Result<()> { } Ok(()) -} \ No newline at end of file +} diff --git a/examples/update_pull_request_branch.rs b/examples/update_pull_request_branch.rs index 28768954..623f12af 100755 --- a/examples/update_pull_request_branch.rs +++ b/examples/update_pull_request_branch.rs @@ -8,7 +8,6 @@ //! octocrab = { path = "../" } //! ``` - use octocrab::Octocrab; #[tokio::main] @@ -16,11 +15,12 @@ async fn main() -> octocrab::Result<()> { let token = std::env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN env variable is required"); let octocrab = Octocrab::builder().personal_token(token).build()?; - let update = octocrab.pulls("XAMPPRocky", "octocrab").update_branch(200).await?; + let update = octocrab + .pulls("XAMPPRocky", "octocrab") + .update_branch(200) + .await?; - println!( - "Result of pull request update: {}", update, - ); + println!("Result of pull request update: {}", update,); Ok(()) } diff --git a/src/api.rs b/src/api.rs index 5c5b12fb..1edb4188 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,6 +1,7 @@ pub mod actions; pub mod activity; pub mod apps; +pub mod commits; pub mod current; pub mod events; pub mod gists; @@ -15,4 +16,3 @@ pub mod repos; pub mod search; pub mod teams; pub mod workflows; -pub mod commits; diff --git a/src/api/actions.rs b/src/api/actions.rs index 6946c759..250d2979 100644 --- a/src/api/actions.rs +++ b/src/api/actions.rs @@ -3,9 +3,7 @@ use snafu::ResultExt; use crate::etag::{EntityTag, Etagged}; use crate::models::{ - workflows::WorkflowListArtifact, - ArtifactId, RepositoryId, RunId, - workflows::WorkflowDispatch + workflows::WorkflowDispatch, workflows::WorkflowListArtifact, ArtifactId, RepositoryId, RunId, }; use crate::{params, FromResponse, Octocrab, Page}; use hyperx::header::{ETag, IfNoneMatch, TypedHeaders}; @@ -93,8 +91,20 @@ pub struct WorkflowDispatchBuilder<'octo> { } impl<'octo> WorkflowDispatchBuilder<'octo> { - pub(crate) fn new(crab: &'octo Octocrab, owner: String, repo: String, workflow_id: String, r#ref: String) -> Self { - let mut this = Self { crab, owner, repo, workflow_id, data: Default::default() }; + pub(crate) fn new( + crab: &'octo Octocrab, + owner: String, + repo: String, + workflow_id: String, + r#ref: String, + ) -> Self { + let mut this = Self { + crab, + owner, + repo, + workflow_id, + data: Default::default(), + }; this.data.r#ref = r#ref; this } @@ -119,11 +129,9 @@ impl<'octo> WorkflowDispatchBuilder<'octo> { ); // this entry point doesn't actually return anything sensible - self.crab._post( - self.crab.absolute_url(route)?, - Some(&self.data), - ) - .await?; + self.crab + ._post(self.crab.absolute_url(route)?, Some(&self.data)) + .await?; Ok(()) } @@ -411,11 +419,12 @@ impl<'octo> ActionsHandler<'octo> { workflow_id: impl Into, r#ref: impl Into, ) -> WorkflowDispatchBuilder<'_> { - WorkflowDispatchBuilder::new(self.crab, + WorkflowDispatchBuilder::new( + self.crab, owner.into(), repo.into(), workflow_id.into(), - r#ref.into() + r#ref.into(), ) } } diff --git a/src/api/activity/notifications.rs b/src/api/activity/notifications.rs index ac29ff97..9edaf25a 100644 --- a/src/api/activity/notifications.rs +++ b/src/api/activity/notifications.rs @@ -1,8 +1,8 @@ //! Github Notifications API -use crate::models::{NotificationId, ThreadId}; use crate::models::activity::Notification; use crate::models::activity::ThreadSubscription; +use crate::models::{NotificationId, ThreadId}; use crate::Octocrab; use crate::Page; @@ -142,7 +142,7 @@ impl<'octo> NotificationsHandler<'octo> { /// ``` pub async fn get_thread_subscription( &self, - thread: ThreadId + thread: ThreadId, ) -> crate::Result { let url = format!("notifications/threads/{}/subscription", thread); @@ -189,10 +189,9 @@ impl<'octo> NotificationsHandler<'octo> { /// # } /// ``` pub async fn delete_thread_subscription(&self, thread: ThreadId) -> crate::Result<()> { - let url = self.crab.absolute_url(format!( - "notifications/threads/{}/subscription", - thread - ))?; + let url = self + .crab + .absolute_url(format!("notifications/threads/{}/subscription", thread))?; let response = self.crab._delete(url, None::<&()>).await?; crate::map_github_error(response).await.map(drop) diff --git a/src/api/apps.rs b/src/api/apps.rs index eb21dec6..545066c6 100644 --- a/src/api/apps.rs +++ b/src/api/apps.rs @@ -1,4 +1,4 @@ -use crate::{Octocrab, models::InstallationId}; +use crate::{models::InstallationId, Octocrab}; mod installations; @@ -32,7 +32,7 @@ impl<'octo> AppsRequestHandler<'octo> { /// ``` pub async fn installation( &self, - installation_id: InstallationId + installation_id: InstallationId, ) -> crate::Result { let route = format!( "app/installations/{installation_id}", diff --git a/src/api/commits.rs b/src/api/commits.rs index d3c3b22d..450d21f0 100644 --- a/src/api/commits.rs +++ b/src/api/commits.rs @@ -1,10 +1,8 @@ //! The commit API. mod create_comment; +pub use self::create_comment::CreateCommentBuilder; use crate::{models, Octocrab}; -pub use self::{ - create_comment::CreateCommentBuilder, -}; pub struct CommitHandler<'octo> { crab: &'octo Octocrab, diff --git a/src/api/commits/create_comment.rs b/src/api/commits/create_comment.rs index ee5b64fb..00a7f0c8 100644 --- a/src/api/commits/create_comment.rs +++ b/src/api/commits/create_comment.rs @@ -14,7 +14,7 @@ pub struct CreateCommentBuilder<'octo, 'r> { line: Option, } -impl<'octo, 'r> CreateCommentBuilder <'octo, 'r> { +impl<'octo, 'r> CreateCommentBuilder<'octo, 'r> { pub(crate) fn new(handler: &'r super::CommitHandler<'octo>, sha: String, body: String) -> Self { Self { handler, @@ -39,9 +39,9 @@ impl<'octo, 'r> CreateCommentBuilder <'octo, 'r> { } /// Relative path of the file to comment on. - /// + /// /// Required if you provide position. - /// + /// /// For example, if you want to comment on a line in the file /// `lib/octocat.rb`, you would provide `lib/octocat.rb`. pub fn path>(mut self, path: impl Into>) -> Self { diff --git a/src/api/gists.rs b/src/api/gists.rs index 8a8916d1..3f7f0e7d 100644 --- a/src/api/gists.rs +++ b/src/api/gists.rs @@ -4,8 +4,11 @@ mod list_commits; use serde::Serialize; use std::collections::BTreeMap; -use crate::{models::gists::{Gist, GistRevision}, Octocrab, Result}; pub use self::list_commits::ListCommitsBuilder; +use crate::{ + models::gists::{Gist, GistRevision}, + Octocrab, Result, +}; /// Handler for GitHub's gist API. /// @@ -59,7 +62,7 @@ impl<'octo> GistsHandler<'octo> { /// # } /// ``` pub fn update(&self, id: impl AsRef) -> UpdateGistBuilder<'octo> { - UpdateGistBuilder::new(self.crab, format!("gists/{id}", id=id.as_ref())) + UpdateGistBuilder::new(self.crab, format!("gists/{id}", id = id.as_ref())) } /// Get a single gist. @@ -74,7 +77,7 @@ impl<'octo> GistsHandler<'octo> { let id = id.as_ref(); self.crab.get(format!("/gists/{}", id), None::<&()>).await } - + /// Get a single gist revision. /// ```no_run /// # async fn run() -> octocrab::Result<()> { @@ -85,10 +88,16 @@ impl<'octo> GistsHandler<'octo> { /// # Ok(()) /// # } /// ``` - pub async fn get_revision(&self, id: impl AsRef, sha1: impl AsRef) -> Result { + pub async fn get_revision( + &self, + id: impl AsRef, + sha1: impl AsRef, + ) -> Result { let id = id.as_ref(); let sha1 = sha1.as_ref(); - self.crab.get(format!("/gists/{}/{}", id, sha1), None::<&()>).await + self.crab + .get(format!("/gists/{}/{}", id, sha1), None::<&()>) + .await } /// List commits for the specified gist. @@ -113,8 +122,6 @@ impl<'octo> GistsHandler<'octo> { pub fn list_commits(&self, gist_id: impl Into) -> list_commits::ListCommitsBuilder { list_commits::ListCommitsBuilder::new(self, gist_id.into()) } - - } #[derive(Debug)] @@ -179,7 +186,7 @@ struct CreateGistFile { pub struct UpdateGistBuilder<'octo> { crab: &'octo Octocrab, gist_path: String, - data: UpdateGist + data: UpdateGist, } impl<'octo> UpdateGistBuilder<'octo> { @@ -187,7 +194,7 @@ impl<'octo> UpdateGistBuilder<'octo> { Self { crab, gist_path, - data: Default::default() + data: Default::default(), } } @@ -197,7 +204,7 @@ impl<'octo> UpdateGistBuilder<'octo> { self } - /// Update the file with the `filename`. + /// Update the file with the `filename`. /// /// The update operation is chosen in further calls to the returned builder. pub fn file(self, filename: impl Into) -> UpdateGistFileBuilder<'octo> { @@ -215,7 +222,7 @@ struct UpdateGist { #[serde(skip_serializing_if = "Option::is_none")] description: Option, #[serde(skip_serializing_if = "Option::is_none")] - files: Option>> + files: Option>>, } #[derive(Debug, Default, Serialize)] @@ -223,14 +230,14 @@ pub struct UpdateGistFile { #[serde(skip_serializing_if = "Option::is_none")] filename: Option, #[serde(skip_serializing_if = "Option::is_none")] - content: Option + content: Option, } pub struct UpdateGistFileBuilder<'octo> { builder: UpdateGistBuilder<'octo>, filename: String, file: Option, - ready: bool + ready: bool, } impl<'octo> UpdateGistFileBuilder<'octo> { @@ -239,13 +246,17 @@ impl<'octo> UpdateGistFileBuilder<'octo> { builder, filename: filename.into(), file: None, - ready: false + ready: false, } } fn build(mut self) -> UpdateGistBuilder<'octo> { if self.ready { - self.builder.data.files.get_or_insert_with(BTreeMap::new).insert(self.filename, self.file); + self.builder + .data + .files + .get_or_insert_with(BTreeMap::new) + .insert(self.filename, self.file); } self.builder } @@ -286,7 +297,7 @@ impl<'octo> UpdateGistFileBuilder<'octo> { } /// Send the `UpdateGist` command to Github for execution. - /// + /// /// This will finalize the update operation before sending. pub async fn send(self) -> Result { self.build().send().await diff --git a/src/api/gists/list_commits.rs b/src/api/gists/list_commits.rs index 1b6fd384..8f708fd8 100644 --- a/src/api/gists/list_commits.rs +++ b/src/api/gists/list_commits.rs @@ -40,4 +40,3 @@ impl<'octo, 'b> ListCommitsBuilder<'octo, 'b> { self.handler.crab.get(url, Some(&self)).await } } - diff --git a/src/api/pulls.rs b/src/api/pulls.rs index 66559765..6e0918e4 100644 --- a/src/api/pulls.rs +++ b/src/api/pulls.rs @@ -2,15 +2,18 @@ mod comment; mod create; -mod update; mod list; mod merge; +mod update; use snafu::ResultExt; use crate::{Octocrab, Page}; -pub use self::{create::CreatePullRequestBuilder, update::UpdatePullRequestBuilder, list::ListPullRequestsBuilder}; +pub use self::{ + create::CreatePullRequestBuilder, list::ListPullRequestsBuilder, + update::UpdatePullRequestBuilder, +}; /// A client to GitHub's pull request API. /// @@ -211,10 +214,7 @@ impl<'octo> PullRequestHandler<'octo> { /// # Ok(()) /// # } /// ``` - pub fn update( - &self, - pull_number: u64, - ) -> update::UpdatePullRequestBuilder<'octo, '_> { + pub fn update(&self, pull_number: u64) -> update::UpdatePullRequestBuilder<'octo, '_> { update::UpdatePullRequestBuilder::new(self, pull_number) } diff --git a/src/api/pulls/update.rs b/src/api/pulls/update.rs index 3b6a9815..2589535f 100644 --- a/src/api/pulls/update.rs +++ b/src/api/pulls/update.rs @@ -52,7 +52,10 @@ impl<'octo, 'b> UpdatePullRequestBuilder<'octo, 'b> { } /// The contents of the pull request. - pub fn state>(mut self, state: impl Into>) -> Self { + pub fn state>( + mut self, + state: impl Into>, + ) -> Self { self.state = state.into().map(A::into); self } diff --git a/src/api/repos.rs b/src/api/repos.rs index ca008a10..74b44437 100644 --- a/src/api/repos.rs +++ b/src/api/repos.rs @@ -15,15 +15,15 @@ mod status; mod tags; use crate::{models, params, Octocrab, Result}; +pub use branches::ListBranchesBuilder; pub use commits::ListCommitsBuilder; -pub use file::{GetContentBuilder, UpdateFileBuilder, DeleteFileBuilder}; +pub use file::{DeleteFileBuilder, GetContentBuilder, UpdateFileBuilder}; pub use generate::GenerateRepositoryBuilder; pub use pulls::ListPullsBuilder; pub use releases::ReleasesHandler; pub use stargazers::ListStarGazersBuilder; pub use status::{CreateStatusBuilder, ListStatusesBuilder}; pub use tags::ListTagsBuilder; -pub use branches::ListBranchesBuilder; /// Handler for GitHub's repository API. /// @@ -525,10 +525,7 @@ impl<'octo> RepoHandler<'octo> { } /// Check if a user is a repository collaborator - pub async fn is_collaborator( - &self, - username: impl AsRef, - ) -> Result { + pub async fn is_collaborator(&self, username: impl AsRef) -> Result { let url = self.crab.absolute_url(format!( "/repos/{owner}/{repo}/collaborators/{username}", owner = self.owner, diff --git a/src/api/repos/generate.rs b/src/api/repos/generate.rs index f4c49645..b8cc2b8f 100644 --- a/src/api/repos/generate.rs +++ b/src/api/repos/generate.rs @@ -1,4 +1,4 @@ -use crate::{Error, repos::RepoHandler}; +use crate::{repos::RepoHandler, Error}; #[derive(serde::Serialize)] pub struct GenerateRepositoryBuilder<'octo, 'r> { @@ -58,16 +58,18 @@ impl<'octo, 'r> GenerateRepositoryBuilder<'octo, 'r> { owner = self.handler.owner, repo = self.handler.repo ); - let request = self.handler + let request = self + .handler .crab .client .post(self.handler.crab.absolute_url(url)?) .body(serde_json::to_string(&self).unwrap()) - .header(reqwest::header::ACCEPT, "application/vnd.github.baptiste-preview+json"); + .header( + reqwest::header::ACCEPT, + "application/vnd.github.baptiste-preview+json", + ); let response = self.handler.crab.execute(request).await?; - crate::map_github_error(response) - .await - .map(drop) + crate::map_github_error(response).await.map(drop) } -} \ No newline at end of file +} diff --git a/src/api/repos/stargazers.rs b/src/api/repos/stargazers.rs index 36c4041e..cab0c072 100644 --- a/src/api/repos/stargazers.rs +++ b/src/api/repos/stargazers.rs @@ -2,46 +2,49 @@ use super::*; #[derive(serde::Serialize)] pub struct ListStarGazersBuilder<'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, + #[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> ListStarGazersBuilder<'octo, 'r> { - pub fn new(handler: &'r RepoHandler<'octo>) -> Self { - Self { - handler, - per_page: None, - page: None, + 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 - } + /// 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 - } + /// 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 url = format!( - "repos/{owner}/{repo}/stargazers", - owner = self.handler.owner, - repo = self.handler.repo - ); + /// Sends the actual request. + pub async fn send(self) -> crate::Result> { + let url = format!( + "repos/{owner}/{repo}/stargazers", + owner = self.handler.owner, + repo = self.handler.repo + ); - let mut headers = reqwest::header::HeaderMap::new(); - headers.insert(ACCEPT, "application/vnd.github.star+json".parse().unwrap()); + let mut headers = reqwest::header::HeaderMap::new(); + headers.insert(ACCEPT, "application/vnd.github.star+json".parse().unwrap()); - self.handler.crab.get_with_headers(url, Some(&self), Some(headers)).await - } + self.handler + .crab + .get_with_headers(url, Some(&self), Some(headers)) + .await + } } diff --git a/src/api/teams.rs b/src/api/teams.rs index a237a9cd..844eaa41 100644 --- a/src/api/teams.rs +++ b/src/api/teams.rs @@ -3,14 +3,15 @@ mod children; mod create; mod edit; +mod invitations; mod list; -mod team_repos; mod members; -mod invitations; +mod team_repos; pub use self::{ children::ListChildTeamsBuilder, create::CreateTeamBuilder, edit::EditTeamBuilder, - list::ListTeamsBuilder, team_repos::TeamRepoHandler, members::ListTeamMembersBuilder, invitations::ListTeamInvitationsBuilder + invitations::ListTeamInvitationsBuilder, list::ListTeamsBuilder, + members::ListTeamMembersBuilder, team_repos::TeamRepoHandler, }; use crate::{models, Octocrab, Result}; diff --git a/src/api/teams/create.rs b/src/api/teams/create.rs index 67f1eee0..a19a00d2 100644 --- a/src/api/teams/create.rs +++ b/src/api/teams/create.rs @@ -1,6 +1,6 @@ use super::*; -use crate::params; use crate::models::TeamId; +use crate::params; #[derive(serde::Serialize)] pub struct CreateTeamBuilder<'octo, 'h, 'a, 'b> { diff --git a/src/api/teams/edit.rs b/src/api/teams/edit.rs index e018a988..ae2b42ff 100644 --- a/src/api/teams/edit.rs +++ b/src/api/teams/edit.rs @@ -1,6 +1,6 @@ use super::*; -use crate::params; use crate::models::TeamId; +use crate::params; #[derive(serde::Serialize)] pub struct EditTeamBuilder<'octo, 'r> { diff --git a/src/api/teams/invitations.rs b/src/api/teams/invitations.rs index 9df470b7..95ae6417 100644 --- a/src/api/teams/invitations.rs +++ b/src/api/teams/invitations.rs @@ -13,7 +13,6 @@ pub struct ListTeamInvitationsBuilder<'octo, 'r> { page: Option, } - impl<'octo, 'r> ListTeamInvitationsBuilder<'octo, 'r> { pub(crate) fn new(handler: &'r TeamHandler<'octo>, slug: String) -> Self { Self { diff --git a/src/lib.rs b/src/lib.rs index 1b983df5..f42d72cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,8 +171,8 @@ use models::{AppId, InstallationId, InstallationToken}; pub use self::{ api::{ - actions, activity, apps, current, events, gists, gitignore, issues, commits, - licenses, markdown, orgs, pulls, repos, search, teams, workflows, ratelimit, + actions, activity, apps, commits, current, events, gists, gitignore, issues, licenses, + markdown, orgs, pulls, ratelimit, repos, search, teams, workflows, }, error::{Error, GitHubError}, from_response::FromResponse, @@ -349,7 +349,7 @@ impl OctocrabBuilder { let auth_state = match self.auth { Auth::None => AuthState::None, - Auth::Basic{ username, password } => AuthState::BasicAuth { username, password }, + Auth::Basic { username, password } => AuthState::BasicAuth { username, password }, Auth::PersonalToken(token) => { hmap.append( reqwest::header::AUTHORIZATION, @@ -739,16 +739,23 @@ impl Octocrab { ) -> Result { self._get_with_headers(url, parameters, None).await } - + /// Send a `GET` request to `route` with optional query parameters and headers, returning /// the body of the response. - pub async fn get_with_headers(&self, route: A, parameters: Option<&P>, headers: Option) -> Result + pub async fn get_with_headers( + &self, + route: A, + parameters: Option<&P>, + headers: Option, + ) -> Result where A: AsRef, P: Serialize + ?Sized, R: FromResponse, { - let response = self._get_with_headers(self.absolute_url(route)?, parameters, headers).await?; + let response = self + ._get_with_headers(self.absolute_url(route)?, parameters, headers) + .await?; R::from_response(crate::map_github_error(response).await?).await } @@ -757,14 +764,14 @@ impl Octocrab { &self, url: impl reqwest::IntoUrl, parameters: Option<&P>, - headers: Option + headers: Option, ) -> Result { let mut request = self.client.get(url); if let Some(parameters) = parameters { request = request.query(parameters); } - + if let Some(headers) = headers { request = request.headers(headers) } @@ -772,7 +779,6 @@ impl Octocrab { self.execute(request).await } - /// Send a `PATCH` request to `route` with optional query parameters, /// returning the body of the response. pub async fn patch(&self, route: A, body: Option<&B>) -> Result @@ -959,7 +965,10 @@ impl Octocrab { AuthState::App(ref app) => { request = request.bearer_auth(app.generate_bearer_token()?); } - AuthState::BasicAuth { ref username, ref password } => { + AuthState::BasicAuth { + ref username, + ref password, + } => { request = request.basic_auth(username, Some(password)); } AuthState::Installation { ref token, .. } => { diff --git a/src/models.rs b/src/models.rs index c112d38a..54d86d10 100644 --- a/src/models.rs +++ b/src/models.rs @@ -10,11 +10,11 @@ use serde::{de, Deserialize, Deserializer, Serialize}; pub mod activity; pub mod apps; +pub mod commits; pub mod events; pub mod gists; pub mod hooks; pub mod issues; -pub mod commits; pub mod orgs; pub mod pulls; pub mod reactions; @@ -545,21 +545,20 @@ pub struct Repository { #[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] pub struct RepositoryFile { - pub name : Option, + pub name: Option, pub key: Option, - pub url : Option, - pub html_url : Option, + pub url: Option, + pub html_url: Option, } - #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] pub struct RepositoryMetrics { - pub health_percentage : u64, + pub health_percentage: u64, pub description: Option, - pub documentation : Option, + pub documentation: Option, pub files: HashMap>, pub updated_at: Option>, - pub content_reports_enabled: Option + pub content_reports_enabled: Option, } #[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)] @@ -771,29 +770,28 @@ pub struct PublicKey { pub key: String, } - #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct RateLimit { pub resources: Resources, - pub rate: Rate, + pub rate: Rate, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Resources { - pub core: Rate, - pub search: Rate, - pub graphql: Option, - pub integration_manifest: Option, - pub scim: Option, - pub source_import: Option, - pub code_scanning_upload: Option, + pub core: Rate, + pub search: Rate, + pub graphql: Option, + pub integration_manifest: Option, + pub scim: Option, + pub source_import: Option, + pub code_scanning_upload: Option, pub actions_runner_registration: Option, } #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Rate { - pub limit: usize, - pub used: usize, + pub limit: usize, + pub used: usize, pub remaining: usize, - pub reset: usize, + pub reset: usize, } diff --git a/src/models/commits.rs b/src/models/commits.rs index f29a037a..2c3b72ca 100644 --- a/src/models/commits.rs +++ b/src/models/commits.rs @@ -21,4 +21,4 @@ pub struct Comment { #[serde(skip_serializing_if = "Option::is_none")] pub updated_at: Option>, pub author_association: String, -} \ No newline at end of file +} diff --git a/src/models/events/payload/pull_request.rs b/src/models/events/payload/pull_request.rs index 43e0fa76..76df1df4 100644 --- a/src/models/events/payload/pull_request.rs +++ b/src/models/events/payload/pull_request.rs @@ -62,9 +62,9 @@ pub struct PullRequestEventChangesFrom { #[cfg(test)] mod test { - use serde_json::json; use super::{PullRequestChanges, PullRequestEventAction, PullRequestEventChangesFrom}; use crate::models::events::{payload::EventPayload, Event}; + use serde_json::json; #[test] fn should_deserialize_action_from_snake_case() { diff --git a/src/models/events/payload/pull_request_review.rs b/src/models/events/payload/pull_request_review.rs index 30ca5e43..234c4f9b 100644 --- a/src/models/events/payload/pull_request_review.rs +++ b/src/models/events/payload/pull_request_review.rs @@ -48,9 +48,7 @@ mod test { #[test] fn should_deserialize_action_from_lowercase() { - let actions = vec![ - (r#""created""#, PullRequestReviewEventAction::Created), - ]; + let actions = vec![(r#""created""#, PullRequestReviewEventAction::Created)]; for (action_str, action) in actions { let deserialized = serde_json::from_str(&action_str).unwrap(); assert_eq!(action, deserialized); diff --git a/src/models/gists.rs b/src/models/gists.rs index 3f9411a9..3c5073f1 100644 --- a/src/models/gists.rs +++ b/src/models/gists.rs @@ -39,16 +39,15 @@ pub struct GistCommit { pub version: String, pub committed_at: DateTime, pub change_status: GistChangeStatus, - pub url: Url + pub url: Url, } - #[non_exhaustive] #[derive(Debug, Deserialize)] pub struct GistChangeStatus { pub total: Option, pub additions: Option, - pub deletions: Option + pub deletions: Option, } #[non_exhaustive] diff --git a/src/models/issues.rs b/src/models/issues.rs index 0bb0b5d0..d4371bbd 100644 --- a/src/models/issues.rs +++ b/src/models/issues.rs @@ -61,7 +61,6 @@ pub struct Comment { pub updated_at: Option>, } - #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] #[non_exhaustive] diff --git a/tests/repos_stargazers_tests.rs b/tests/repos_stargazers_tests.rs index 0fe10e91..72e9bfd4 100644 --- a/tests/repos_stargazers_tests.rs +++ b/tests/repos_stargazers_tests.rs @@ -5,37 +5,37 @@ use mock_error::setup_error_handler; use octocrab::{models::StarGazer, Octocrab, Page}; use serde::{Deserialize, Serialize}; use wiremock::{ - matchers::{method, path}, - Mock, MockServer, ResponseTemplate, + matchers::{method, path}, + Mock, MockServer, ResponseTemplate, }; #[derive(Serialize, Deserialize)] struct FakePage { - items: Vec, + items: Vec, } async fn setup_api(template: ResponseTemplate) -> MockServer { - let owner = "owner"; - let repo = "repo"; - let mock_server = MockServer::start().await; - Mock::given(method("GET")) - .and(path(format!("/repos/{}/{}/stargazers", owner, repo))) - .respond_with(template) - .mount(&mock_server) + let owner = "owner"; + let repo = "repo"; + let mock_server = MockServer::start().await; + Mock::given(method("GET")) + .and(path(format!("/repos/{}/{}/stargazers", owner, repo))) + .respond_with(template) + .mount(&mock_server) + .await; + setup_error_handler( + &mock_server, + &format!( + "GET on /repo/{}/{}/stargazers was not received", + owner, repo + ), + ) .await; - setup_error_handler( - &mock_server, - &format!( - "GET on /repo/{}/{}/stargazers was not received", - owner, repo - ), - ) - .await; - mock_server + mock_server } fn setup_octocrab(uri: &str) -> Octocrab { - Octocrab::builder().base_url(uri).unwrap().build().unwrap() + Octocrab::builder().base_url(uri).unwrap().build().unwrap() } const OWNER: &str = "owner"; @@ -43,52 +43,50 @@ const REPO: &str = "repo"; #[tokio::test] async fn should_return_page_with_users() { - let star_gazers: Vec = serde_json::from_str(include_str!("resources/stargazers.json")).unwrap(); - let login1: String = star_gazers[0].user.as_ref().unwrap().login.clone(); - let page_response = FakePage { - items: star_gazers, - }; - let template = ResponseTemplate::new(200).set_body_json(&page_response); - let mock_server = setup_api(template).await; - let client = setup_octocrab(&mock_server.uri()); - let repos = client.repos(OWNER.to_owned(), REPO.to_owned()); - let result = repos.list_stargazers().send().await; - assert!( - result.is_ok(), - "expected successful result, got error: {:#?}", - result - ); - match result.unwrap() { - Page { items, .. } => { - assert_eq!(items.len(), 3); - assert_eq!(items[0].user.as_ref().unwrap().login, login1); + let star_gazers: Vec = + serde_json::from_str(include_str!("resources/stargazers.json")).unwrap(); + let login1: String = star_gazers[0].user.as_ref().unwrap().login.clone(); + let page_response = FakePage { items: star_gazers }; + let template = ResponseTemplate::new(200).set_body_json(&page_response); + let mock_server = setup_api(template).await; + let client = setup_octocrab(&mock_server.uri()); + let repos = client.repos(OWNER.to_owned(), REPO.to_owned()); + let result = repos.list_stargazers().send().await; + assert!( + result.is_ok(), + "expected successful result, got error: {:#?}", + result + ); + match result.unwrap() { + Page { items, .. } => { + assert_eq!(items.len(), 3); + assert_eq!(items[0].user.as_ref().unwrap().login, login1); + } } - } } #[tokio::test] async fn should_return_page_with_all_users() { - let star_gazers: Vec = serde_json::from_str(include_str!("resources/stargazers.json")).unwrap(); - let login1: String = star_gazers[0].user.as_ref().unwrap().login.clone(); - let login2: String = star_gazers[1].user.as_ref().unwrap().login.clone(); - let page_response = FakePage { - items: star_gazers, - }; - let template = ResponseTemplate::new(200).set_body_json(&page_response); - let mock_server = setup_api(template).await; - let client = setup_octocrab(&mock_server.uri()); - - let page = client - .repos(OWNER.to_owned(), REPO.to_owned()) - .list_stargazers() - .per_page(100) - .send() - .await - .unwrap(); + let star_gazers: Vec = + serde_json::from_str(include_str!("resources/stargazers.json")).unwrap(); + let login1: String = star_gazers[0].user.as_ref().unwrap().login.clone(); + let login2: String = star_gazers[1].user.as_ref().unwrap().login.clone(); + let page_response = FakePage { items: star_gazers }; + let template = ResponseTemplate::new(200).set_body_json(&page_response); + let mock_server = setup_api(template).await; + let client = setup_octocrab(&mock_server.uri()); - let result = client.all_pages(page).await.unwrap(); - assert_eq!(result.len(), 3); - assert_eq!(result[0].user.as_ref().unwrap().login, login1); - assert_eq!(result[1].user.as_ref().unwrap().login, login2); - assert_eq!(result[2].user, None); + let page = client + .repos(OWNER.to_owned(), REPO.to_owned()) + .list_stargazers() + .per_page(100) + .send() + .await + .unwrap(); + + let result = client.all_pages(page).await.unwrap(); + assert_eq!(result.len(), 3); + assert_eq!(result[0].user.as_ref().unwrap().login, login1); + assert_eq!(result[1].user.as_ref().unwrap().login, login2); + assert_eq!(result[2].user, None); } diff --git a/tests/team_invitations_tests.rs b/tests/team_invitations_tests.rs index 5c1f3fe9..01f70c31 100644 --- a/tests/team_invitations_tests.rs +++ b/tests/team_invitations_tests.rs @@ -2,7 +2,7 @@ mod mock_error; use mock_error::setup_error_handler; -use octocrab::{models::{teams::TeamInvitation}, Octocrab, Page}; +use octocrab::{models::teams::TeamInvitation, Octocrab, Page}; use serde::{Deserialize, Serialize}; use wiremock::{ matchers::{method, path}, @@ -26,7 +26,10 @@ async fn setup_api(template: ResponseTemplate) -> MockServer { .await; setup_error_handler( &mock_server, - &format!("GET on /orgs/{}/teams/{}/invitations was not received", org, team), + &format!( + "GET on /orgs/{}/teams/{}/invitations was not received", + org, team + ), ) .await; mock_server diff --git a/tests/team_members_tests.rs b/tests/team_members_tests.rs index 7bea6619..8c2e2f2b 100644 --- a/tests/team_members_tests.rs +++ b/tests/team_members_tests.rs @@ -2,7 +2,7 @@ mod mock_error; use mock_error::setup_error_handler; -use octocrab::{models::{User}, Octocrab, Page}; +use octocrab::{models::User, Octocrab, Page}; use serde::{Deserialize, Serialize}; use wiremock::{ matchers::{method, path}, @@ -26,7 +26,10 @@ async fn setup_api(template: ResponseTemplate) -> MockServer { .await; setup_error_handler( &mock_server, - &format!("GET on /orgs/{}/teams/{}/members was not received", org, team), + &format!( + "GET on /orgs/{}/teams/{}/members was not received", + org, team + ), ) .await; mock_server