feat: add render-md json input flow

This commit is contained in:
2026-04-08 22:50:30 +08:00
parent 75e3239a16
commit 2b9c50af2e
8 changed files with 528 additions and 8 deletions
+94
View File
@@ -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"));
}