11use anyhow:: Result ;
2- use std:: path:: PathBuf ;
32use tracing:: info;
43
54#[ path = "pr/comments.rs" ]
65mod comments;
6+ #[ path = "pr/context.rs" ]
7+ mod context;
78#[ path = "pr/gh.rs" ]
89mod gh;
10+ #[ path = "pr/review_flow.rs" ]
11+ mod review_flow;
12+ #[ path = "pr/summary_flow.rs" ]
13+ mod summary_flow;
914
10- use crate :: adapters;
1115use crate :: config;
12- use crate :: core;
1316use crate :: output:: OutputFormat ;
14- use crate :: review;
1517
16- use comments:: post_review_comments;
17- use gh:: { fetch_pr_diff, fetch_pr_metadata, resolve_pr_number} ;
18+ use context:: prepare_pr_context;
19+ use review_flow:: run_pr_review_flow;
20+ use summary_flow:: run_pr_summary_flow;
1821
1922pub async fn pr_command (
2023 number : Option < u32 > ,
@@ -24,72 +27,19 @@ pub async fn pr_command(
2427 config : config:: Config ,
2528 format : OutputFormat ,
2629) -> Result < ( ) > {
27- let pr_number = resolve_pr_number ( number, repo. as_deref ( ) ) ?;
30+ let context = prepare_pr_context ( number, repo. as_deref ( ) ) ?;
2831
29- info ! ( "Reviewing PR #{}" , pr_number) ;
32+ info ! ( "Reviewing PR #{}" , context . pr_number) ;
3033
31- let git = core:: GitIntegration :: new ( "." ) ?;
32- let repo_root = git. workdir ( ) . unwrap_or_else ( || PathBuf :: from ( "." ) ) ;
33- if let Ok ( branch) = git. get_current_branch ( ) {
34- info ! ( "Current branch: {}" , branch) ;
35- }
36- if let Ok ( Some ( remote) ) = git. get_remote_url ( ) {
37- info ! ( "Remote URL: {}" , remote) ;
38- }
39-
40- let diff_content = fetch_pr_diff ( & pr_number, repo. as_deref ( ) ) ?;
41-
42- if diff_content. is_empty ( ) {
34+ if context. diff_content . is_empty ( ) {
4335 println ! ( "No changes in PR" ) ;
4436 return Ok ( ( ) ) ;
4537 }
4638
4739 if summary {
48- let diffs = core:: DiffParser :: parse_unified_diff ( & diff_content) ?;
49- let git = core:: GitIntegration :: new ( "." ) ?;
50-
51- let fast_config = config. to_model_config_for_role ( config:: ModelRole :: Fast ) ;
52- let adapter = adapters:: llm:: create_adapter ( & fast_config) ?;
53- let options = core:: SummaryOptions {
54- include_diagram : config. smart_review_diagram ,
55- } ;
56- let pr_summary = core:: PRSummaryGenerator :: generate_summary_with_options (
57- & diffs,
58- & git,
59- adapter. as_ref ( ) ,
60- options,
61- )
62- . await ?;
63-
64- println ! ( "{}" , pr_summary. to_markdown( ) ) ;
40+ run_pr_summary_flow ( & config, & context. diff_content ) . await ?;
6541 return Ok ( ( ) ) ;
6642 }
6743
68- let review_result =
69- review:: review_diff_content_raw ( & diff_content, config. clone ( ) , & repo_root) . await ?;
70- let comments = review_result. comments ;
71-
72- if post_comments {
73- info ! ( "Posting {} comments to PR" , comments. len( ) ) ;
74- let metadata = fetch_pr_metadata ( & pr_number, repo. as_deref ( ) ) ?;
75- let stats = post_review_comments (
76- & pr_number,
77- repo. as_deref ( ) ,
78- & metadata,
79- & comments,
80- & config. rule_priority ,
81- ) ?;
82-
83- println ! (
84- "Posted {} comments to PR #{} (inline: {}, fallback: {}, summary: updated)" ,
85- comments. len( ) ,
86- pr_number,
87- stats. inline_posted,
88- stats. fallback_posted
89- ) ;
90- } else {
91- crate :: output:: output_comments ( & comments, None , format, & config. rule_priority ) . await ?;
92- }
93-
94- Ok ( ( ) )
44+ run_pr_review_flow ( & context, repo. as_deref ( ) , post_comments, & config, format) . await
9545}
0 commit comments