diff --git a/README.en.md b/README.en.md index d6cb915..3b61827 100644 --- a/README.en.md +++ b/README.en.md @@ -59,6 +59,10 @@ gitea-pr-review render-md --in pr.json --out pr.md ````md # `#` +> Numbering: Review `.`; Comment `..`; Reply `...` + + + ## Metadata ### Commits @@ -68,7 +72,7 @@ gitea-pr-review render-md --in pr.json --out pr.md total: files, +, - - : +, - -## Review 1 () +## Review . () > ### Comment .. diff --git a/README.md b/README.md index f26fb34..defce9a 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,10 @@ gitea-pr-review render-md --in pr.json --out pr.md ````md # `#` +> 编号规则:Review `.`;Comment `..`;Reply `...` + + + ## Metadata ### Commits @@ -68,7 +72,7 @@ gitea-pr-review render-md --in pr.json --out pr.md total: files, +, - - : +, - -## Review 1 () +## Review . () > ### Comment .. diff --git a/src/model.rs b/src/model.rs index ad42280..5b54f33 100644 --- a/src/model.rs +++ b/src/model.rs @@ -14,6 +14,7 @@ pub struct PrMeta { pub repo: String, pub pr_index: i64, pub title: String, + pub description: Option, pub state: String, pub author: String, pub base_branch: String, diff --git a/src/normalize.rs b/src/normalize.rs index 0aaa028..abd1136 100644 --- a/src/normalize.rs +++ b/src/normalize.rs @@ -32,6 +32,7 @@ pub fn normalize_bundle(repo: &str, bundle: PullBundleDto) -> PrReviewDocument { repo: repo.to_string(), pr_index: pull.number, title: pull.title, + description: pull.body, state: pull.state, author: pull.user.login, base_branch: pull.base.ref_name, diff --git a/src/render/markdown.rs b/src/render/markdown.rs index 65dda56..7698532 100644 --- a/src/render/markdown.rs +++ b/src/render/markdown.rs @@ -62,6 +62,18 @@ pub fn render_markdown(doc: &PrReviewDocument) -> String { "# {} `#{}` {}\n\n", doc.meta.repo, doc.meta.pr_index, doc.meta.title )); + out.push_str( + "> 编号规则:Review `.`;Comment `..`;Reply `...`\n\n", + ); + let pr_description = doc + .meta + .description + .as_deref() + .map(str::trim) + .filter(|value| !value.is_empty()) + .unwrap_or("_PR 描述为空_"); + out.push_str(pr_description); + out.push_str("\n\n"); out.push_str("## Metadata\n\n"); out.push_str(&format!("- state: {}\n", doc.meta.state)); @@ -100,7 +112,8 @@ pub fn render_markdown(doc: &PrReviewDocument) -> String { for (review_index, review) in doc.reviews.iter().enumerate() { out.push_str(&format!( - "## Review {} ({})\n\n", + "## Review {}.{} ({})\n\n", + doc.meta.pr_index, review_index + 1, review.state )); diff --git a/tests/e2e_smoke_tests.rs b/tests/e2e_smoke_tests.rs index 777926a..ad7f3e4 100644 --- a/tests/e2e_smoke_tests.rs +++ b/tests/e2e_smoke_tests.rs @@ -12,6 +12,7 @@ fn render_md_reads_json_and_outputs_markdown_to_stdout() { "repo": "org/repo", "pr_index": 1, "title": "t", + "description": "PR body", "state": "open", "author": "a", "base_branch": "main", @@ -54,6 +55,7 @@ fn render_md_writes_to_out_file_when_requested() { "repo": "org/repo", "pr_index": 2, "title": "t2", + "description": "PR body", "state": "open", "author": "a", "base_branch": "main", @@ -220,7 +222,7 @@ fn fetch_writes_markdown_to_stdout_by_default() { assert!(stdout.contains("# org/repo `#7` Fix parser")); assert!(stdout.contains("## Commits")); assert!(stdout.contains("## Diff Stat")); - assert!(stdout.contains("## Review 1 (COMMENT)")); + assert!(stdout.contains("## Review 7.1 (COMMENT)")); } #[test] diff --git a/tests/render_json_tests.rs b/tests/render_json_tests.rs index 62fa126..fb9df36 100644 --- a/tests/render_json_tests.rs +++ b/tests/render_json_tests.rs @@ -9,6 +9,7 @@ fn model_json_roundtrip() { repo: "org/repo".into(), pr_index: 9, title: "feat: x".into(), + description: Some("desc".into()), state: "open".into(), author: "alice".into(), base_branch: "main".into(), diff --git a/tests/render_markdown_tests.rs b/tests/render_markdown_tests.rs index 7f1123d..67dcb9b 100644 --- a/tests/render_markdown_tests.rs +++ b/tests/render_markdown_tests.rs @@ -11,6 +11,7 @@ fn render_markdown_includes_expected_sections_and_preserves_comment_markdown() { repo: "org/repo".into(), pr_index: 7, title: "Fix parser".into(), + description: Some("PR body".into()), state: "open".into(), author: "alice".into(), base_branch: "main".into(), @@ -73,12 +74,14 @@ fn render_markdown_includes_expected_sections_and_preserves_comment_markdown() { assert!(md.contains("## Metadata")); assert!(md.contains("## Commits")); assert!(md.contains("## Diff Stat")); - assert!(md.contains("## Review 1 (COMMENT)")); + assert!(md.contains("> 编号规则:Review `.`;Comment `..`;Reply `...`")); + assert!(md.contains("PR body")); + assert!(md.contains("## Review 7.1 (COMMENT)")); assert!(md.contains("### Comment 7.1.1")); assert!(md.contains("src/main.rs:9")); assert!(md.contains("### Reply 7.1.1.1")); assert!(md.contains("src/main.rs:12")); - let review_pos = md.find("## Review 1 (COMMENT)").unwrap(); + let review_pos = md.find("## Review 7.1 (COMMENT)").unwrap(); let comment_pos = md.find("### Comment 7.1.1").unwrap(); assert!(comment_pos > review_pos); assert!(!md.contains("## Comments (No Review)")); @@ -95,6 +98,7 @@ fn render_markdown_uses_minimal_fence_for_plain_text() { repo: "org/repo".into(), pr_index: 1, title: "T".into(), + description: None, state: "open".into(), author: "alice".into(), base_branch: "main".into(),