feat: add markdown renderer for review documents
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
use gitea_pr_review::model::{
|
||||
CommentItem, CommentThread, CommitItem, DiffStat, FileStat, PrMeta, PrReviewDocument,
|
||||
ReviewItem,
|
||||
};
|
||||
use gitea_pr_review::render::markdown::render_markdown;
|
||||
|
||||
#[test]
|
||||
fn render_markdown_includes_expected_sections_and_preserves_comment_markdown() {
|
||||
let doc = PrReviewDocument {
|
||||
meta: PrMeta {
|
||||
repo: "org/repo".into(),
|
||||
pr_index: 7,
|
||||
title: "Fix parser".into(),
|
||||
state: "open".into(),
|
||||
author: "alice".into(),
|
||||
base_branch: "main".into(),
|
||||
head_branch: "feat/a".into(),
|
||||
created_at: "2026-04-08T10:00:00Z".into(),
|
||||
updated_at: "2026-04-08T11:00:00Z".into(),
|
||||
merged_at: None,
|
||||
},
|
||||
commits: vec![CommitItem {
|
||||
sha: "abcdef0123456789".into(),
|
||||
short_sha: "abcdef0".into(),
|
||||
title: "fix: parser".into(),
|
||||
author: "alice".into(),
|
||||
date: "2026-04-08T10:10:00Z".into(),
|
||||
}],
|
||||
diff_stat: DiffStat {
|
||||
files_changed: 1,
|
||||
additions: 3,
|
||||
deletions: 1,
|
||||
files: vec![FileStat {
|
||||
path: "src/main.rs".into(),
|
||||
additions: 3,
|
||||
deletions: 1,
|
||||
}],
|
||||
},
|
||||
reviews: vec![ReviewItem {
|
||||
id: 1,
|
||||
state: "COMMENT".into(),
|
||||
reviewer: "bob".into(),
|
||||
submitted_at: Some("2026-04-08T11:00:00Z".into()),
|
||||
}],
|
||||
threads: vec![CommentThread {
|
||||
thread_id: "t1".into(),
|
||||
file_path: Some("src/main.rs".into()),
|
||||
line: Some(9),
|
||||
root_comment: CommentItem {
|
||||
id: 11,
|
||||
user: "bob".into(),
|
||||
created_at: "2026-04-08T11:01:00Z".into(),
|
||||
body: "```rs\nlet x = 1;\n```".into(),
|
||||
},
|
||||
replies: vec![CommentItem {
|
||||
id: 12,
|
||||
user: "alice".into(),
|
||||
created_at: "2026-04-08T11:02:00Z".into(),
|
||||
body: "looks good".into(),
|
||||
}],
|
||||
}],
|
||||
};
|
||||
|
||||
let md = render_markdown(&doc);
|
||||
|
||||
assert!(md.contains("# org/repo `#7` Fix parser"));
|
||||
assert!(md.contains("## Metadata"));
|
||||
assert!(md.contains("## Commits"));
|
||||
assert!(md.contains("## Diff Stat"));
|
||||
assert!(md.contains("## Review 1 (COMMENT)"));
|
||||
assert!(md.contains("### Comment 1.1"));
|
||||
assert!(md.contains("### Reply 1.1"));
|
||||
assert!(md.contains("````md"));
|
||||
assert!(md.contains("```rs\nlet x = 1;\n```"));
|
||||
assert!(md.contains("looks good"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_markdown_uses_minimal_fence_for_plain_text() {
|
||||
let body = "plain text";
|
||||
let doc = PrReviewDocument {
|
||||
meta: PrMeta {
|
||||
repo: "org/repo".into(),
|
||||
pr_index: 1,
|
||||
title: "T".into(),
|
||||
state: "open".into(),
|
||||
author: "alice".into(),
|
||||
base_branch: "main".into(),
|
||||
head_branch: "feat".into(),
|
||||
created_at: "2026-04-08T10:00:00Z".into(),
|
||||
updated_at: "2026-04-08T10:00:00Z".into(),
|
||||
merged_at: None,
|
||||
},
|
||||
commits: vec![],
|
||||
diff_stat: DiffStat {
|
||||
files_changed: 0,
|
||||
additions: 0,
|
||||
deletions: 0,
|
||||
files: vec![],
|
||||
},
|
||||
reviews: vec![],
|
||||
threads: vec![CommentThread {
|
||||
thread_id: "t1".into(),
|
||||
file_path: None,
|
||||
line: None,
|
||||
root_comment: CommentItem {
|
||||
id: 1,
|
||||
user: "bob".into(),
|
||||
created_at: "2026-04-08T11:00:00Z".into(),
|
||||
body: body.into(),
|
||||
},
|
||||
replies: vec![],
|
||||
}],
|
||||
};
|
||||
|
||||
let md = render_markdown(&doc);
|
||||
assert!(md.contains("```md\nplain text\n```"));
|
||||
}
|
||||
Reference in New Issue
Block a user