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

Remove hyperx dep; Manually inspect 'Link' header #258

Merged
merged 2 commits into from
Mar 21, 2023
Merged
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
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ serde = { version = "1.0.126", features = ["derive"] }
serde_json = "1.0.64"
serde_path_to_error = "0.1.4"
async-trait = "0.1.50"
chrono = { version = "0.4.19", default-features = false, features = ["serde", "clock"] }
chrono = { version = "0.4.19", default-features = false, features = [
"serde",
"clock",
] }
url = { version = "2.2.2", features = ["serde"] }
hyperx = "1.3.0"
snafu = { version = "0.7", features = ["backtraces"] }
once_cell = "1.7.2"
arc-swap = "1.3.0"
Expand Down
42 changes: 23 additions & 19 deletions src/api/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ 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};
use reqwest::{header::HeaderMap, Method, StatusCode};

pub struct ListWorkflowRunArtifacts<'octo> {
Expand Down Expand Up @@ -62,15 +59,11 @@ impl<'octo> ListWorkflowRunArtifacts<'octo> {
);
let mut headers = HeaderMap::new();
if let Some(etag) = self.etag {
headers.encode(&IfNoneMatch::Items(vec![etag]));
EntityTag::insert_if_none_match_header(&mut headers, etag)?;
}
let builder = self.crab.client.request(Method::GET, &url).headers(headers);
let response = self.crab.execute(builder).await?;
let etag = response
.headers()
.decode::<ETag>()
.ok()
.map(|ETag(tag)| tag);
let etag = EntityTag::extract_from_response(&response);
if response.status() == StatusCode::NOT_MODIFIED {
Ok(Etagged { etag, value: None })
} else {
Expand All @@ -93,8 +86,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 +124,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 +414,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
9 changes: 2 additions & 7 deletions src/api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
models::events,
FromResponse, Octocrab, Page,
};
use hyperx::header::{ETag, IfNoneMatch, TypedHeaders};
use reqwest::{header::HeaderMap, Method, StatusCode};

pub struct EventsBuilder<'octo> {
Expand Down Expand Up @@ -60,7 +59,7 @@ impl<'octo> EventsBuilder<'octo> {
let url = format!("{base_url}events", base_url = self.crab.base_url);
let mut headers = HeaderMap::new();
if let Some(etag) = self.headers.etag {
headers.encode(&IfNoneMatch::Items(vec![etag]));
EntityTag::insert_if_none_match_header(&mut headers, etag)?;
}
let builder = self
.crab
Expand All @@ -69,11 +68,7 @@ impl<'octo> EventsBuilder<'octo> {
.headers(headers)
.query(&self.params);
let response = self.crab.execute(builder).await?;
let etag = response
.headers()
.decode::<ETag>()
.ok()
.map(|ETag(tag)| tag);
let etag = EntityTag::extract_from_response(&response);
if response.status() == StatusCode::NOT_MODIFIED {
Ok(Etagged { etag, value: None })
} else {
Expand Down
9 changes: 2 additions & 7 deletions src/api/repos/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
repos::RepoHandler,
FromResponse, Page,
};
use hyperx::header::{ETag, IfNoneMatch, TypedHeaders};
use reqwest::{header::HeaderMap, Method, StatusCode};

pub struct ListRepoEventsBuilder<'octo, 'handler> {
Expand Down Expand Up @@ -66,7 +65,7 @@ impl<'octo, 'handler> ListRepoEventsBuilder<'octo, 'handler> {
);
let mut headers = HeaderMap::new();
if let Some(etag) = self.headers.etag {
headers.encode(&IfNoneMatch::Items(vec![etag]));
EntityTag::insert_if_none_match_header(&mut headers, etag)?;
}
let builder = self
.handler
Expand All @@ -76,11 +75,7 @@ impl<'octo, 'handler> ListRepoEventsBuilder<'octo, 'handler> {
.headers(headers)
.query(&self.params);
let response = self.handler.crab.execute(builder).await?;
let etag = response
.headers()
.decode::<ETag>()
.ok()
.map(|ETag(tag)| tag);
let etag = EntityTag::extract_from_response(&response);
if response.status() == StatusCode::NOT_MODIFIED {
Ok(Etagged { etag, value: None })
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ pub enum Error {
source: url::ParseError,
backtrace: Backtrace,
},
InvalidHeaderValue {
source: reqwest::header::InvalidHeaderValue,
backtrace: Backtrace,
},
#[snafu(display("HTTP Error: {}\n\nFound at {}", source, backtrace))]
Http {
source: reqwest::Error,
Expand Down
Loading