wip: pull request view & md rendering
This commit is contained in:
25
src/api.rs
25
src/api.rs
@@ -1,3 +1,4 @@
|
||||
use reqwest::Method;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::query;
|
||||
@@ -36,8 +37,9 @@ pub(crate) enum Error {
|
||||
#[cfg(debug_assertions)]
|
||||
MissingMockFixture(String),
|
||||
Github(GithubError),
|
||||
MalformedResponse(serde_json::Error),
|
||||
MalformedResponse(String),
|
||||
HttpError(reqwest::Error),
|
||||
GraphQLError(Vec<graphql_client::Error>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -66,6 +68,16 @@ impl QueryContext {
|
||||
.header("User-Agent", "kennethnym")
|
||||
.bearer_auth(&auth.access_token))
|
||||
}
|
||||
|
||||
fn github_graphql_request<V>(
|
||||
&self,
|
||||
request: &graphql_client::QueryBody<V>,
|
||||
) -> Result<reqwest::RequestBuilder, Error>
|
||||
where
|
||||
V: serde::Serialize,
|
||||
{
|
||||
Ok(self.github_request(Method::POST, "/graphql")?.json(request))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -88,7 +100,7 @@ impl From<reqwest::Error> for Error {
|
||||
|
||||
impl From<serde_json::Error> for Error {
|
||||
fn from(value: serde_json::Error) -> Self {
|
||||
Self::MalformedResponse(value)
|
||||
Self::MalformedResponse(value.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,10 +130,13 @@ where
|
||||
|
||||
async fn parse_graphql_response<T>(
|
||||
res: reqwest::Response,
|
||||
) -> Result<graphql_client::Response<T>, Error>
|
||||
) -> Result<(graphql_client::Response<T>, T), Error>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
{
|
||||
let data: graphql_client::Response<T> = res.json().await?;
|
||||
Ok(data)
|
||||
let mut body: graphql_client::Response<T> = res.json().await?;
|
||||
match body.data.take() {
|
||||
None => Err(Error::GraphQLError(body.errors.unwrap_or_default())),
|
||||
Some(data) => Ok((body, data)),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user