Skip to content

Commit

Permalink
APPSEC-2612: Be more explicit about types in make_graphql_request
Browse files Browse the repository at this point in the history
  • Loading branch information
fearnoeval committed Apr 26, 2023
1 parent 80d0111 commit b5a1e4a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ghommit"
version = "0.0.3"
version = "0.0.4"
edition = "2021"

[dependencies]
Expand Down
19 changes: 11 additions & 8 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ impl GitHubClient<'_> {
}

fn get_http_client(&self, maybe_timeout_seconds: Option<u64>) -> Result<reqwest::blocking::Client, String> {
let timeout_seconds = match maybe_timeout_seconds {
Some(timeout_seconds) => timeout_seconds,
None => 60,
};
let timeout_seconds = maybe_timeout_seconds.unwrap_or_else(|| 60);

let maybe_client = reqwest::blocking::Client::builder().timeout(Duration::from_secs(timeout_seconds)).build();

Expand Down Expand Up @@ -200,10 +197,16 @@ impl GitHubClient<'_> {
Err(e) => Err(format!("Error occurred while reading GraphQL response body as text: {}", e.to_string()))?,
};

match serde_json::from_str(&text) {
let data = match serde_json::from_str::<R>(&text) {
Ok(typed_result) => typed_result,
Err(e) => Err(format!("Error occurred while deserializing GraphQL response: {}: {}", e.to_string(), text)),
}
Err(e) => {
let err_str = e.to_string();
let type_str = std::any::type_name::<R>();
Err(format!("Error occurred while deserializing GraphQL response to {}: {}: {}", type_str, err_str, text))?
}
};

Ok(data)
}

fn does_branch_exist(&self, config: &Config) -> Result<bool, String> {
Expand Down Expand Up @@ -392,7 +395,7 @@ pub mod request {
}
}

mod response {
pub mod response {
use serde::Deserialize;

// > CreateCommitOnBranch
Expand Down

0 comments on commit b5a1e4a

Please # to comment.