|
1 | 1 | use serde::Serialize;
|
2 | 2 | use structopt::StructOpt;
|
3 | 3 |
|
4 |
| -use rover_client::operations::graph::check; |
5 |
| -use rover_client::shared::GitContext; |
| 4 | +use rover_client::operations::graph::check::{self, GraphCheckInput}; |
| 5 | +use rover_client::shared::{CheckConfig, GitContext}; |
6 | 6 |
|
| 7 | +use crate::command::shared::check::print_check_response; |
7 | 8 | use crate::command::RoverStdout;
|
8 | 9 | use crate::utils::client::StudioClientConfig;
|
9 | 10 | use crate::utils::loaders::load_schema_from_flag;
|
10 | 11 | use crate::utils::parsers::{
|
11 | 12 | parse_graph_ref, parse_query_count_threshold, parse_query_percentage_threshold,
|
12 | 13 | parse_schema_source, parse_validation_period, GraphRef, SchemaSource, ValidationPeriod,
|
13 | 14 | };
|
14 |
| -use crate::utils::table::{self, cell, row}; |
15 | 15 | use crate::Result;
|
16 | 16 |
|
17 | 17 | #[derive(Debug, Serialize, StructOpt)]
|
@@ -56,79 +56,29 @@ impl Check {
|
56 | 56 | git_context: GitContext,
|
57 | 57 | ) -> Result<RoverStdout> {
|
58 | 58 | let client = client_config.get_client(&self.profile_name)?;
|
59 |
| - let sdl = load_schema_from_flag(&self.schema, std::io::stdin())?; |
| 59 | + let proposed_schema = load_schema_from_flag(&self.schema, std::io::stdin())?; |
| 60 | + |
| 61 | + eprintln!( |
| 62 | + "Checking the proposed schema against metrics from {}", |
| 63 | + &self.graph |
| 64 | + ); |
| 65 | + |
60 | 66 | let res = check::run(
|
61 |
| - check::check_schema_query::Variables { |
| 67 | + GraphCheckInput { |
62 | 68 | graph_id: self.graph.name.clone(),
|
63 |
| - variant: Some(self.graph.variant.clone()), |
64 |
| - schema: Some(sdl), |
65 |
| - git_context: git_context.into(), |
66 |
| - config: check::check_schema_query::HistoricQueryParameters { |
| 69 | + variant: self.graph.variant.clone(), |
| 70 | + proposed_schema, |
| 71 | + git_context, |
| 72 | + config: CheckConfig { |
67 | 73 | query_count_threshold: self.query_count_threshold,
|
68 | 74 | query_count_threshold_percentage: self.query_percentage_threshold,
|
69 |
| - from: self.validation_period.clone().unwrap_or_default().from, |
70 |
| - to: self.validation_period.clone().unwrap_or_default().to, |
71 |
| - // we don't support configuring these, but we can't leave them out |
72 |
| - excluded_clients: None, |
73 |
| - ignored_operations: None, |
74 |
| - included_variants: None, |
| 75 | + validation_period_from: self.validation_period.clone().unwrap_or_default().from, |
| 76 | + validation_period_to: self.validation_period.clone().unwrap_or_default().to, |
75 | 77 | },
|
76 | 78 | },
|
77 | 79 | &client,
|
78 | 80 | )?;
|
79 | 81 |
|
80 |
| - eprintln!( |
81 |
| - "Validated the proposed subgraph against metrics from {}", |
82 |
| - &self.graph |
83 |
| - ); |
84 |
| - |
85 |
| - let num_changes = res.changes.len(); |
86 |
| - |
87 |
| - let msg = match num_changes { |
88 |
| - 0 => "There is no difference between the proposed graph and the graph that already exists in the graph registry. Try making a change to your proposed graph before running this command.".to_string(), |
89 |
| - _ => format!("Compared {} schema changes against {} operations", res.changes.len(), res.number_of_checked_operations), |
90 |
| - }; |
91 |
| - |
92 |
| - eprintln!("{}", &msg); |
93 |
| - |
94 |
| - let num_failures = print_changes(&res.changes); |
95 |
| - |
96 |
| - if let Some(url) = res.target_url { |
97 |
| - eprintln!("View full details at {}", &url); |
98 |
| - } |
99 |
| - |
100 |
| - match num_failures { |
101 |
| - 0 => Ok(RoverStdout::None), |
102 |
| - 1 => Err(anyhow::anyhow!("Encountered 1 failure.").into()), |
103 |
| - _ => Err(anyhow::anyhow!("Encountered {} failures.", num_failures).into()), |
104 |
| - } |
105 |
| - } |
106 |
| -} |
107 |
| - |
108 |
| -fn print_changes( |
109 |
| - checks: &[check::check_schema_query::CheckSchemaQueryServiceCheckSchemaDiffToPreviousChanges], |
110 |
| -) -> u64 { |
111 |
| - let mut num_failures = 0; |
112 |
| - |
113 |
| - if !checks.is_empty() { |
114 |
| - let mut table = table::get_table(); |
115 |
| - |
116 |
| - // bc => sets top row to be bold and center |
117 |
| - table.add_row(row![bc => "Change", "Code", "Description"]); |
118 |
| - for check in checks { |
119 |
| - let change = match check.severity { |
120 |
| - check::check_schema_query::ChangeSeverity::NOTICE => "PASS", |
121 |
| - check::check_schema_query::ChangeSeverity::FAILURE => { |
122 |
| - num_failures += 1; |
123 |
| - "FAIL" |
124 |
| - } |
125 |
| - _ => unreachable!("Unknown change severity"), |
126 |
| - }; |
127 |
| - table.add_row(row![change, check.code, check.description]); |
128 |
| - } |
129 |
| - |
130 |
| - eprintln!("{}", table); |
| 82 | + print_check_response(res) |
131 | 83 | }
|
132 |
| - |
133 |
| - num_failures |
134 | 84 | }
|
0 commit comments