feat: add render-md json input flow
This commit is contained in:
@@ -16,13 +16,7 @@ fn parse_fetch_default_format() {
|
||||
|
||||
#[test]
|
||||
fn parse_render_md_requires_input() {
|
||||
let cli = Cli::try_parse_from([
|
||||
"gitea-pr-review",
|
||||
"render-md",
|
||||
"--in",
|
||||
"sample.json",
|
||||
])
|
||||
.unwrap();
|
||||
let cli = Cli::try_parse_from(["gitea-pr-review", "render-md", "--in", "sample.json"]).unwrap();
|
||||
|
||||
match cli.command {
|
||||
Commands::RenderMd(args) => {
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
use assert_cmd::Command;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
#[test]
|
||||
fn render_md_reads_json_and_outputs_markdown_to_stdout() {
|
||||
let input = NamedTempFile::new().unwrap();
|
||||
std::fs::write(
|
||||
input.path(),
|
||||
r#"{
|
||||
"meta": {
|
||||
"repo": "org/repo",
|
||||
"pr_index": 1,
|
||||
"title": "t",
|
||||
"state": "open",
|
||||
"author": "a",
|
||||
"base_branch": "main",
|
||||
"head_branch": "f",
|
||||
"created_at": "2026-04-08T10:00:00Z",
|
||||
"updated_at": "2026-04-08T11:00:00Z",
|
||||
"merged_at": null
|
||||
},
|
||||
"commits": [],
|
||||
"diff_stat": {
|
||||
"files_changed": 0,
|
||||
"additions": 0,
|
||||
"deletions": 0,
|
||||
"files": []
|
||||
},
|
||||
"reviews": [],
|
||||
"threads": []
|
||||
}"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("gitea-pr-review").unwrap();
|
||||
let assert = cmd
|
||||
.args(["render-md", "--in", input.path().to_str().unwrap()])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
|
||||
assert!(stdout.contains("# org/repo `#1` t"));
|
||||
assert!(stdout.contains("## Metadata"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_md_writes_to_out_file_when_requested() {
|
||||
let input = NamedTempFile::new().unwrap();
|
||||
std::fs::write(
|
||||
input.path(),
|
||||
r#"{
|
||||
"meta": {
|
||||
"repo": "org/repo",
|
||||
"pr_index": 2,
|
||||
"title": "t2",
|
||||
"state": "open",
|
||||
"author": "a",
|
||||
"base_branch": "main",
|
||||
"head_branch": "f",
|
||||
"created_at": "2026-04-08T10:00:00Z",
|
||||
"updated_at": "2026-04-08T11:00:00Z",
|
||||
"merged_at": null
|
||||
},
|
||||
"commits": [],
|
||||
"diff_stat": {
|
||||
"files_changed": 0,
|
||||
"additions": 0,
|
||||
"deletions": 0,
|
||||
"files": []
|
||||
},
|
||||
"reviews": [],
|
||||
"threads": []
|
||||
}"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let output = NamedTempFile::new().unwrap();
|
||||
|
||||
Command::cargo_bin("gitea-pr-review")
|
||||
.unwrap()
|
||||
.args([
|
||||
"render-md",
|
||||
"--in",
|
||||
input.path().to_str().unwrap(),
|
||||
"--out",
|
||||
output.path().to_str().unwrap(),
|
||||
])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let written = std::fs::read_to_string(output.path()).unwrap();
|
||||
assert!(written.contains("# org/repo `#2` t2"));
|
||||
assert!(written.contains("## Metadata"));
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
use gitea_pr_review::model::{CommentItem, CommentThread, DiffStat, FileStat, PrMeta, PrReviewDocument};
|
||||
use gitea_pr_review::model::{
|
||||
CommentItem, CommentThread, DiffStat, FileStat, PrMeta, PrReviewDocument,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn model_json_roundtrip() {
|
||||
|
||||
Reference in New Issue
Block a user