19 lines
518 B
Rust
19 lines
518 B
Rust
use crate::model::PrReviewDocument;
|
|
use crate::OUTPUT_VERSION;
|
|
|
|
pub fn render_json(doc: &PrReviewDocument) -> anyhow::Result<String> {
|
|
Ok(serde_json::to_string_pretty(doc)?)
|
|
}
|
|
|
|
pub fn parse_json(input: &str) -> anyhow::Result<PrReviewDocument> {
|
|
let doc: PrReviewDocument = serde_json::from_str(input)?;
|
|
if doc.version != OUTPUT_VERSION {
|
|
anyhow::bail!(
|
|
"unsupported document version: {}, expected {}",
|
|
doc.version,
|
|
OUTPUT_VERSION
|
|
);
|
|
}
|
|
Ok(doc)
|
|
}
|