Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace reqwest with http and hyper. #294

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ futures-util = { version = "0.3.15", optional = true }
secrecy = "0.8.0"
cfg-if = "1.0.0"
either = "1.8.0"
http = "0.2.8"
hyper = "0.14.23"

[dev-dependencies]
tokio = { version = "1.17.0", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion examples/device_flow.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use either::Either;
use reqwest::header::ACCEPT;
use http::header::ACCEPT;
use std::time::Duration;

#[tokio::main]
Expand Down
55 changes: 35 additions & 20 deletions src/api/actions.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! GitHub Actions
use snafu::ResultExt;
use std::str::FromStr;
use url::Url;

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 http::{header::HeaderMap, Method, StatusCode};
use hyperx::header::{ETag, IfNoneMatch, TypedHeaders};
use reqwest::{header::HeaderMap, Method, StatusCode};

pub struct ListWorkflowRunArtifacts<'octo> {
crab: &'octo Octocrab,
Expand Down Expand Up @@ -93,8 +93,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 +131,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 @@ -242,14 +252,18 @@ impl<'octo> ActionsHandler<'octo> {
&self,
response: reqwest::Response,
) -> crate::Result<bytes::Bytes> {
let data_response =
if let Some(redirect) = response.headers().get(reqwest::header::LOCATION) {
let location = redirect.to_str().expect("Location URL not valid str");
let data_response = if let Some(redirect) = response.headers().get(http::header::LOCATION) {
let location = redirect.to_str().expect("Location URL not valid str");

self.crab._get(location, None::<&()>).await?
} else {
response
};
self.crab
._get(
Url::from_str(location).context(crate::error::UrlSnafu)?,
None::<&()>,
)
.await?
} else {
response
};

data_response.bytes().await.context(crate::error::HttpSnafu)
}
Expand Down Expand Up @@ -411,11 +425,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
2 changes: 1 addition & 1 deletion src/api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
models::events,
FromResponse, Octocrab, Page,
};
use http::{header::HeaderMap, Method, StatusCode};
use hyperx::header::{ETag, IfNoneMatch, TypedHeaders};
use reqwest::{header::HeaderMap, Method, StatusCode};

pub struct EventsBuilder<'octo> {
crab: &'octo Octocrab,
Expand Down
2 changes: 1 addition & 1 deletion src/api/gitignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'octo> GitignoreHandler<'octo> {
.crab
.client
.get(self.crab.absolute_url(route)?)
.header(reqwest::header::ACCEPT, crate::format_media_type("raw"));
.header(http::header::ACCEPT, crate::format_media_type("raw"));

self.crab
.execute(request)
Expand Down
14 changes: 7 additions & 7 deletions src/api/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<'octo> IssueHandler<'octo> {
);

self.crab
.post(route, Some(&serde_json::json!({ "assignees": assignees })))
.post(&route, Some(&serde_json::json!({ "assignees": assignees })))
.await
}

Expand Down Expand Up @@ -336,7 +336,7 @@ impl<'octo> IssueHandler<'octo> {
);

self.crab
.post(route, Some(&serde_json::json!({ "labels": labels })))
.post(&route, Some(&serde_json::json!({ "labels": labels })))
.await
}

Expand Down Expand Up @@ -417,7 +417,7 @@ impl<'octo> IssueHandler<'octo> {

self.crab
.post(
route,
&route,
Some(&serde_json::json!({
"name": name.as_ref(),
"color": color.as_ref(),
Expand Down Expand Up @@ -531,7 +531,7 @@ impl<'octo> IssueHandler<'octo> {
);

self.crab
.post(route, Some(&serde_json::json!({ "body": body.as_ref() })))
.post(&route, Some(&serde_json::json!({ "body": body.as_ref() })))
.await
}

Expand Down Expand Up @@ -579,7 +579,7 @@ impl<'octo> IssueHandler<'octo> {
);

self.crab
.post(route, Some(&serde_json::json!({ "body": body.as_ref() })))
.post(&route, Some(&serde_json::json!({ "body": body.as_ref() })))
.await
}

Expand Down Expand Up @@ -926,7 +926,7 @@ impl<'octo> IssueHandler<'octo> {
);

self.crab
.post(route, Some(&serde_json::json!({ "content": content })))
.post(&route, Some(&serde_json::json!({ "content": content })))
.await
}

Expand All @@ -953,7 +953,7 @@ impl<'octo> IssueHandler<'octo> {
);

self.crab
.post(route, Some(&serde_json::json!({ "content": content })))
.post(&route, Some(&serde_json::json!({ "content": content })))
.await
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/issues/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'octo, 'r> CreateIssueBuilder<'octo, 'r> {
repo = self.handler.repo,
);

self.handler.crab.post(route, Some(&self)).await
self.handler.crab.post(&route, Some(&self)).await
}

/// The contents of the issue.
Expand Down
2 changes: 1 addition & 1 deletion src/api/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'octo> MarkdownHandler<'octo> {
.crab
.client
.post(self.crab.absolute_url("markdown/raw")?)
.header(reqwest::header::CONTENT_TYPE, "text/x-markdown")
.header(http::header::CONTENT_TYPE, "text/x-markdown")
.body(text.into());

self.crab
Expand Down
4 changes: 2 additions & 2 deletions src/api/orgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<'octo> OrgHandler<'octo> {

let body = role.map(|role| serde_json::json!({ "role": role }));

self.crab.post(url, body.as_ref()).await
self.crab.post(&url, body.as_ref()).await
}

/// Check if a user is, publicly or privately, a member of the organization.
Expand Down Expand Up @@ -164,7 +164,7 @@ impl<'octo> OrgHandler<'octo> {
let route = format!("orgs/{org}/hooks", org = self.owner);
let res = self
.crab
.post(self.crab.absolute_url(route)?, Some(&hook))
.post(self.crab.absolute_url(route)?.as_str(), Some(&hook))
.await?;

Ok(res)
Expand Down
22 changes: 11 additions & 11 deletions src/api/pulls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -132,7 +135,7 @@ impl<'octo> PullRequestHandler<'octo> {
.crab
.client
.get(self.crab.absolute_url(route)?)
.header(reqwest::header::ACCEPT, crate::format_media_type("diff"));
.header(http::header::ACCEPT, crate::format_media_type("diff"));

let response = crate::map_github_error(self.crab.execute(request).await?).await?;

Expand All @@ -158,7 +161,7 @@ impl<'octo> PullRequestHandler<'octo> {
.crab
.client
.get(self.crab.absolute_url(route)?)
.header(reqwest::header::ACCEPT, crate::format_media_type("patch"));
.header(http::header::ACCEPT, crate::format_media_type("patch"));

let response = crate::map_github_error(self.crab.execute(request).await?).await?;

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -288,7 +288,7 @@ impl<'octo> PullRequestHandler<'octo> {
map.insert("reviewers".to_string(), reviewers.into().into());
map.insert("team_reviewers".to_string(), team_reviewers.into().into());

self.crab.post(url, Some(&map)).await
self.crab.post(&url, Some(&map)).await
}

/// List all `FileDiff`s associated with the pull request.
Expand Down Expand Up @@ -378,7 +378,7 @@ impl<'octo> PullRequestHandler<'octo> {

if let Some(media_type) = self.media_type {
request = request.header(
reqwest::header::ACCEPT,
http::header::ACCEPT,
crate::format_media_type(&media_type.to_string()),
);
}
Expand Down Expand Up @@ -439,7 +439,7 @@ impl<'octo> PullRequestHandler<'octo> {

if let Some(media_type) = self.media_type {
request = request.header(
reqwest::header::ACCEPT,
http::header::ACCEPT,
crate::format_media_type(&media_type.to_string()),
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/api/repos.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The repositories API.

use reqwest::header::ACCEPT;
use http::header::ACCEPT;

mod branches;
mod commits;
Expand All @@ -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.
///
Expand Down Expand Up @@ -180,7 +180,7 @@ impl<'octo> RepoHandler<'octo> {
);
self.crab
.post(
url,
&url,
Some(&serde_json::json!({
"ref": reference.full_ref_url(),
"sha": sha.into(),
Expand Down Expand Up @@ -485,7 +485,7 @@ impl<'octo> RepoHandler<'octo> {
repo = self.repo,
path = path.as_ref(),
))?;
let mut request = self.crab.request_builder(url, reqwest::Method::GET);
let mut request = self.crab.request_builder(url.as_str(), http::Method::GET);
request = request.query(&[("ref", &reference.into().0)]);
request = request.header(ACCEPT, "application/vnd.github.v3.raw");
self.crab.execute(request).await
Expand Down
2 changes: 1 addition & 1 deletion src/api/repos/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
repos::RepoHandler,
FromResponse, Page,
};
use http::{header::HeaderMap, Method, StatusCode};
use hyperx::header::{ETag, IfNoneMatch, TypedHeaders};
use reqwest::{header::HeaderMap, Method, StatusCode};

pub struct ListRepoEventsBuilder<'octo, 'handler> {
handler: &'handler RepoHandler<'octo>,
Expand Down
2 changes: 1 addition & 1 deletion src/api/repos/forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'octo, 'r> CreateForkBuilder<'octo, 'r> {
owner = self.handler.owner,
repo = self.handler.repo
);
self.handler.crab.post(url, Some(&self)).await
self.handler.crab.post(&url, Some(&self)).await
}
}

Expand Down
Loading