-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: begin adding shared types and consolidate check operations (#652)
- Loading branch information
1 parent
9e83b88
commit e29b87b
Showing
86 changed files
with
531 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...r-client/src/query/config/who_am_i/mod.rs → ...ent/src/operations/config/who_am_i/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod types; | ||
|
||
pub mod query_runner; | ||
pub mod runner; | ||
pub use types::{Actor, ConfigWhoAmIInput, RegistryIdentity}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...client/src/query/config/who_am_i/types.rs → ...t/src/operations/config/who_am_i/types.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod runner; | ||
mod types; | ||
|
||
pub use runner::run; | ||
pub use types::GraphCheckInput; |
63 changes: 27 additions & 36 deletions
63
crates/rover-client/src/query/graph/check.rs → ...ient/src/operations/graph/check/runner.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,67 @@ | ||
use crate::blocking::StudioClient; | ||
use crate::operations::graph::check::types::{ | ||
GraphCheckInput, MutationChangeSeverity, MutationResponseData, | ||
}; | ||
use crate::shared::CheckResponse; | ||
use crate::RoverClientError; | ||
use graphql_client::*; | ||
|
||
use reqwest::Url; | ||
use graphql_client::*; | ||
|
||
type Timestamp = String; | ||
#[derive(GraphQLQuery)] | ||
// The paths are relative to the directory where your `Cargo.toml` is located. | ||
// Both json and the GraphQL schema language are supported as sources for the schema | ||
#[graphql( | ||
query_path = "src/query/graph/check.graphql", | ||
query_path = "src/operations/graph/check/check_mutation.graphql", | ||
schema_path = ".schema/schema.graphql", | ||
response_derives = "PartialEq, Debug, Serialize, Deserialize", | ||
deprecated = "warn" | ||
)] | ||
/// This struct is used to generate the module containing `Variables` and | ||
/// `ResponseData` structs. | ||
/// Snake case of this name is the mod name. i.e. check_schema_query | ||
pub struct CheckSchemaQuery; | ||
/// Snake case of this name is the mod name. i.e. graph_check_mutation | ||
pub(crate) struct GraphCheckMutation; | ||
|
||
/// The main function to be used from this module. | ||
/// This function takes a proposed schema and validates it against a published | ||
/// schema. | ||
pub fn run( | ||
variables: check_schema_query::Variables, | ||
input: GraphCheckInput, | ||
client: &StudioClient, | ||
) -> Result<CheckResponse, RoverClientError> { | ||
let graph = variables.graph_id.clone(); | ||
let data = client.post::<CheckSchemaQuery>(variables)?; | ||
let graph = input.graph_id.clone(); | ||
let data = client.post::<GraphCheckMutation>(input.into())?; | ||
get_check_response_from_data(data, graph) | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct CheckResponse { | ||
pub target_url: Option<Url>, | ||
pub number_of_checked_operations: i64, | ||
pub change_severity: check_schema_query::ChangeSeverity, | ||
pub changes: Vec<check_schema_query::CheckSchemaQueryServiceCheckSchemaDiffToPreviousChanges>, | ||
} | ||
|
||
fn get_check_response_from_data( | ||
data: check_schema_query::ResponseData, | ||
data: MutationResponseData, | ||
graph: String, | ||
) -> Result<CheckResponse, RoverClientError> { | ||
let service = data.service.ok_or(RoverClientError::NoService { graph })?; | ||
let target_url = get_url(service.check_schema.target_url); | ||
let target_url = service.check_schema.target_url; | ||
|
||
let diff_to_previous = service.check_schema.diff_to_previous; | ||
|
||
let number_of_checked_operations = diff_to_previous.number_of_checked_operations.unwrap_or(0); | ||
|
||
let change_severity = diff_to_previous.severity; | ||
let changes = diff_to_previous.changes; | ||
let change_severity = diff_to_previous.severity.into(); | ||
let mut changes = Vec::with_capacity(diff_to_previous.changes.len()); | ||
let mut num_failures = 0; | ||
for change in diff_to_previous.changes { | ||
if let MutationChangeSeverity::FAILURE = change.severity { | ||
num_failures += 1; | ||
} | ||
changes.push(change.into()); | ||
} | ||
|
||
Ok(CheckResponse { | ||
let check_response = CheckResponse { | ||
target_url, | ||
number_of_checked_operations, | ||
change_severity, | ||
changes, | ||
}) | ||
} | ||
change_severity, | ||
num_failures, | ||
}; | ||
|
||
fn get_url(url: Option<String>) -> Option<Url> { | ||
match url { | ||
Some(url) => { | ||
let url = Url::parse(&url); | ||
match url { | ||
Ok(url) => Some(url), | ||
// if the API returns an invalid URL, don't put it in the response | ||
Err(_) => None, | ||
} | ||
} | ||
None => None, | ||
} | ||
check_response.check_for_failures() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use crate::operations::graph::check::runner::graph_check_mutation; | ||
use crate::shared::{ChangeSeverity, CheckConfig, GitContext, SchemaChange}; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct GraphCheckInput { | ||
pub graph_id: String, | ||
pub variant: String, | ||
pub proposed_schema: String, | ||
pub git_context: GitContext, | ||
pub config: CheckConfig, | ||
} | ||
|
||
impl From<GraphCheckInput> for MutationVariables { | ||
fn from(input: GraphCheckInput) -> Self { | ||
Self { | ||
graph_id: input.graph_id, | ||
variant: Some(input.variant), | ||
proposed_schema: Some(input.proposed_schema), | ||
config: input.config.into(), | ||
git_context: input.git_context.into(), | ||
} | ||
} | ||
} | ||
|
||
type MutationConfig = graph_check_mutation::HistoricQueryParameters; | ||
impl From<CheckConfig> for MutationConfig { | ||
fn from(input: CheckConfig) -> Self { | ||
Self { | ||
query_count_threshold: input.query_count_threshold, | ||
query_count_threshold_percentage: input.query_count_threshold_percentage, | ||
from: input.validation_period_from, | ||
to: input.validation_period_to, | ||
// we don't support configuring these, but we can't leave them out | ||
excluded_clients: None, | ||
ignored_operations: None, | ||
included_variants: None, | ||
} | ||
} | ||
} | ||
|
||
type MutationVariables = graph_check_mutation::Variables; | ||
pub(crate) type MutationResponseData = graph_check_mutation::ResponseData; | ||
|
||
pub(crate) type MutationChangeSeverity = graph_check_mutation::ChangeSeverity; | ||
impl From<MutationChangeSeverity> for ChangeSeverity { | ||
fn from(severity: MutationChangeSeverity) -> Self { | ||
match severity { | ||
MutationChangeSeverity::NOTICE => ChangeSeverity::PASS, | ||
MutationChangeSeverity::FAILURE => ChangeSeverity::FAIL, | ||
_ => ChangeSeverity::unreachable(), | ||
} | ||
} | ||
} | ||
|
||
impl From<ChangeSeverity> for MutationChangeSeverity { | ||
fn from(severity: ChangeSeverity) -> Self { | ||
match severity { | ||
ChangeSeverity::PASS => MutationChangeSeverity::NOTICE, | ||
ChangeSeverity::FAIL => MutationChangeSeverity::FAILURE, | ||
} | ||
} | ||
} | ||
|
||
type MutationSchemaChange = | ||
graph_check_mutation::GraphCheckMutationServiceCheckSchemaDiffToPreviousChanges; | ||
impl From<SchemaChange> for MutationSchemaChange { | ||
fn from(schema_change: SchemaChange) -> MutationSchemaChange { | ||
MutationSchemaChange { | ||
severity: schema_change.severity.into(), | ||
code: schema_change.code, | ||
description: schema_change.description, | ||
} | ||
} | ||
} | ||
|
||
impl From<MutationSchemaChange> for SchemaChange { | ||
fn from(schema_change: MutationSchemaChange) -> SchemaChange { | ||
SchemaChange { | ||
severity: schema_change.severity.into(), | ||
code: schema_change.code, | ||
description: schema_change.description, | ||
} | ||
} | ||
} | ||
|
||
type MutationGitContextInput = graph_check_mutation::GitContextInput; | ||
impl From<GitContext> for MutationGitContextInput { | ||
fn from(git_context: GitContext) -> MutationGitContextInput { | ||
MutationGitContextInput { | ||
branch: git_context.branch, | ||
commit: git_context.commit, | ||
committer: git_context.author, | ||
remote_url: git_context.remote_url, | ||
message: None, | ||
} | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.