Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Mar 20, 2023
1 parent dbead9a commit 9292aa4
Show file tree
Hide file tree
Showing 32 changed files with 255 additions and 219 deletions.
6 changes: 4 additions & 2 deletions examples/create_repo_from_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,4 +19,4 @@ async fn main() -> octocrab::Result<()> {
.await?;

Ok(())
}
}
5 changes: 4 additions & 1 deletion examples/get_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/github_app_authentication_manual.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use octocrab::models::{InstallationToken, InstallationRepositories};
use octocrab::models::{InstallationRepositories, InstallationToken};
use octocrab::params::apps::CreateInstallationAccessToken;
use octocrab::Octocrab;

Expand Down
7 changes: 5 additions & 2 deletions examples/is_collab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -15,4 +18,4 @@ async fn main() -> octocrab::Result<()> {
}

Ok(())
}
}
10 changes: 5 additions & 5 deletions examples/update_pull_request_branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
//! octocrab = { path = "../" }
//! ```

use octocrab::Octocrab;

#[tokio::main]
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(())
}
2 changes: 1 addition & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,4 +16,3 @@ pub mod repos;
pub mod search;
pub mod teams;
pub mod workflows;
pub mod commits;
33 changes: 21 additions & 12 deletions src/api/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
}
Expand All @@ -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(())
}
Expand Down Expand Up @@ -411,11 +419,12 @@ impl<'octo> ActionsHandler<'octo> {
workflow_id: impl Into<String>,
r#ref: impl Into<String>,
) -> WorkflowDispatchBuilder<'_> {
WorkflowDispatchBuilder::new(self.crab,
WorkflowDispatchBuilder::new(
self.crab,
owner.into(),
repo.into(),
workflow_id.into(),
r#ref.into()
r#ref.into(),
)
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/api/activity/notifications.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -142,7 +142,7 @@ impl<'octo> NotificationsHandler<'octo> {
/// ```
pub async fn get_thread_subscription(
&self,
thread: ThreadId
thread: ThreadId,
) -> crate::Result<ThreadSubscription> {
let url = format!("notifications/threads/{}/subscription", thread);

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/api/apps.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Octocrab, models::InstallationId};
use crate::{models::InstallationId, Octocrab};

mod installations;

Expand Down Expand Up @@ -32,7 +32,7 @@ impl<'octo> AppsRequestHandler<'octo> {
/// ```
pub async fn installation(
&self,
installation_id: InstallationId
installation_id: InstallationId,
) -> crate::Result<crate::models::Installation> {
let route = format!(
"app/installations/{installation_id}",
Expand Down
4 changes: 1 addition & 3 deletions src/api/commits.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/api/commits/create_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct CreateCommentBuilder<'octo, 'r> {
line: Option<u64>,
}

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,
Expand All @@ -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<A: Into<String>>(mut self, path: impl Into<Option<A>>) -> Self {
Expand Down
43 changes: 27 additions & 16 deletions src/api/gists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -59,7 +62,7 @@ impl<'octo> GistsHandler<'octo> {
/// # }
/// ```
pub fn update(&self, id: impl AsRef<str>) -> 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.
Expand All @@ -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<()> {
Expand All @@ -85,10 +88,16 @@ impl<'octo> GistsHandler<'octo> {
/// # Ok(())
/// # }
/// ```
pub async fn get_revision(&self, id: impl AsRef<str>, sha1: impl AsRef<str>) -> Result<GistRevision> {
pub async fn get_revision(
&self,
id: impl AsRef<str>,
sha1: impl AsRef<str>,
) -> Result<GistRevision> {
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.
Expand All @@ -113,8 +122,6 @@ impl<'octo> GistsHandler<'octo> {
pub fn list_commits(&self, gist_id: impl Into<String>) -> list_commits::ListCommitsBuilder {
list_commits::ListCommitsBuilder::new(self, gist_id.into())
}


}

#[derive(Debug)]
Expand Down Expand Up @@ -179,15 +186,15 @@ struct CreateGistFile {
pub struct UpdateGistBuilder<'octo> {
crab: &'octo Octocrab,
gist_path: String,
data: UpdateGist
data: UpdateGist,
}

impl<'octo> UpdateGistBuilder<'octo> {
fn new(crab: &'octo Octocrab, gist_path: String) -> Self {
Self {
crab,
gist_path,
data: Default::default()
data: Default::default(),
}
}

Expand All @@ -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<String>) -> UpdateGistFileBuilder<'octo> {
Expand All @@ -215,22 +222,22 @@ struct UpdateGist {
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
files: Option<BTreeMap<String, Option<UpdateGistFile>>>
files: Option<BTreeMap<String, Option<UpdateGistFile>>>,
}

#[derive(Debug, Default, Serialize)]
pub struct UpdateGistFile {
#[serde(skip_serializing_if = "Option::is_none")]
filename: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
content: Option<String>
content: Option<String>,
}

pub struct UpdateGistFileBuilder<'octo> {
builder: UpdateGistBuilder<'octo>,
filename: String,
file: Option<UpdateGistFile>,
ready: bool
ready: bool,
}

impl<'octo> UpdateGistFileBuilder<'octo> {
Expand All @@ -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
}
Expand Down Expand Up @@ -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<Gist> {
self.build().send().await
Expand Down
1 change: 0 additions & 1 deletion src/api/gists/list_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ impl<'octo, 'b> ListCommitsBuilder<'octo, 'b> {
self.handler.crab.get(url, Some(&self)).await
}
}

Loading

0 comments on commit 9292aa4

Please sign in to comment.