zagens_runtime/cli/
pr_prompt.rs1#[derive(Debug, Clone, Default)]
4pub(crate) struct GhPullRequest {
5 pub(crate) title: String,
6 pub(crate) body: String,
7 pub(crate) base: String,
8 pub(crate) head: String,
9 pub(crate) url: String,
10}
11
12pub(crate) fn format_pr_prompt(number: u32, view: &GhPullRequest, diff: &str) -> String {
13 const MAX_DIFF_BYTES: usize = 200 * 1024;
14 let diff_section = if diff.len() > MAX_DIFF_BYTES {
15 let cut = (0..=MAX_DIFF_BYTES)
16 .rev()
17 .find(|&i| diff.is_char_boundary(i))
18 .unwrap_or(0);
19 format!(
20 "{}\n\n[…diff truncated at {} KiB; ask me to fetch more if needed]\n",
21 &diff[..cut],
22 MAX_DIFF_BYTES / 1024
23 )
24 } else {
25 diff.to_string()
26 };
27 let body = if view.body.trim().is_empty() {
28 "(no description)".to_string()
29 } else {
30 view.body.trim().to_string()
31 };
32 let title = if view.title.trim().is_empty() {
33 format!("(PR #{number})")
34 } else {
35 view.title.trim().to_string()
36 };
37 let branches = match (view.base.is_empty(), view.head.is_empty()) {
38 (false, false) => format!("{} ← {}", view.base, view.head),
39 (false, true) => view.base.clone(),
40 (true, false) => view.head.clone(),
41 _ => "(unknown)".to_string(),
42 };
43 format!(
44 "Review PR #{number} — {title}\n\
45 \n\
46 URL: {url}\n\
47 Branches: {branches}\n\
48 \n\
49 ## Description\n\
50 \n\
51 {body}\n\
52 \n\
53 ## Diff\n\
54 \n\
55 ```diff\n\
56 {diff_section}\n\
57 ```\n",
58 url = if view.url.is_empty() {
59 "(unavailable)"
60 } else {
61 view.url.as_str()
62 },
63 )
64}