Skip to content

Commit 6253011

Browse files
committed
refactor: split feedback input conversion helpers
Separate review-session expansion from feedback label normalization so input conversion paths can evolve without sharing unrelated helper code. Made-with: Cursor
1 parent 917c120 commit 6253011

5 files changed

Lines changed: 82 additions & 70 deletions

File tree

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
- [ ] `src/commands/eval/types.rs`: split fixture, pattern, report, and run-option types if churn keeps touching unrelated structs.
8181
- [ ] `src/commands/feedback_eval/types.rs`: separate input payload types from report/output types.
8282
- [x] `src/commands/feedback_eval/input/loading.rs`: split format detection from JSON parsing/loading.
83-
- [ ] `src/commands/feedback_eval/input/conversion.rs`: split review-session conversion from label normalization helpers.
83+
- [x] `src/commands/feedback_eval/input/conversion.rs`: split review-session conversion from label normalization helpers.
8484
- [ ] `src/commands/pr.rs`: separate summary-only flow, full review flow, and comment-posting orchestration.
8585
- [ ] `src/commands/pr/gh.rs`: carve PR resolution, diff fetching, and metadata fetching.
8686
- [ ] `src/commands/git/suggest.rs`: split commit-message prompting from PR-title prompting and response extraction.
Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,9 @@
1-
use crate::core;
2-
use crate::review;
3-
use crate::server::state::ReviewSession;
4-
5-
use super::super::{FeedbackEvalComment, LoadedFeedbackEvalInput};
6-
7-
pub(super) fn extend_from_review_session(
8-
loaded: &mut LoadedFeedbackEvalInput,
9-
review_id: Option<String>,
10-
session: ReviewSession,
11-
) {
12-
let repo = session
13-
.event
14-
.as_ref()
15-
.and_then(|event| event.github_repo.clone());
16-
let pr_number = session.event.as_ref().and_then(|event| event.github_pr);
17-
let title = session.event.as_ref().and_then(|event| event.title.clone());
18-
19-
loaded.total_reviews_seen += 1;
20-
loaded.total_comments_seen += session.comments.len();
21-
loaded
22-
.comments
23-
.extend(session.comments.into_iter().filter_map(|comment| {
24-
feedback_comment_from_comment(
25-
"review-session",
26-
review_id.clone(),
27-
repo.clone(),
28-
pr_number,
29-
title.clone(),
30-
comment,
31-
)
32-
}));
33-
}
34-
35-
pub(super) fn feedback_comment_from_comment(
36-
source_kind: &str,
37-
review_id: Option<String>,
38-
repo: Option<String>,
39-
pr_number: Option<u32>,
40-
title: Option<String>,
41-
comment: core::Comment,
42-
) -> Option<FeedbackEvalComment> {
43-
let accepted = normalize_feedback_label(comment.feedback.as_deref()?)?;
44-
let file_patterns = review::derive_file_patterns(&comment.file_path);
45-
46-
Some(FeedbackEvalComment {
47-
source_kind: source_kind.to_string(),
48-
review_id,
49-
repo,
50-
pr_number,
51-
title,
52-
file_path: Some(comment.file_path),
53-
line_number: Some(comment.line_number),
54-
file_patterns,
55-
content: comment.content,
56-
category: comment.category.to_string(),
57-
severity: Some(comment.severity.to_string()),
58-
confidence: Some(comment.confidence),
59-
accepted,
60-
})
61-
}
62-
63-
fn normalize_feedback_label(label: &str) -> Option<bool> {
64-
match label.trim().to_ascii_lowercase().as_str() {
65-
"accept" | "accepted" => Some(true),
66-
"reject" | "rejected" => Some(false),
67-
_ => None,
68-
}
69-
}
1+
#[path = "conversion/comment.rs"]
2+
mod comment;
3+
#[path = "conversion/labels.rs"]
4+
mod labels;
5+
#[path = "conversion/session.rs"]
6+
mod session;
7+
8+
pub(super) use comment::feedback_comment_from_comment;
9+
pub(super) use session::extend_from_review_session;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use crate::core;
2+
use crate::review;
3+
4+
use super::super::super::FeedbackEvalComment;
5+
use super::labels::normalize_feedback_label;
6+
7+
pub(in super::super) fn feedback_comment_from_comment(
8+
source_kind: &str,
9+
review_id: Option<String>,
10+
repo: Option<String>,
11+
pr_number: Option<u32>,
12+
title: Option<String>,
13+
comment: core::Comment,
14+
) -> Option<FeedbackEvalComment> {
15+
let accepted = normalize_feedback_label(comment.feedback.as_deref()?)?;
16+
let file_patterns = review::derive_file_patterns(&comment.file_path);
17+
18+
Some(FeedbackEvalComment {
19+
source_kind: source_kind.to_string(),
20+
review_id,
21+
repo,
22+
pr_number,
23+
title,
24+
file_path: Some(comment.file_path),
25+
line_number: Some(comment.line_number),
26+
file_patterns,
27+
content: comment.content,
28+
category: comment.category.to_string(),
29+
severity: Some(comment.severity.to_string()),
30+
confidence: Some(comment.confidence),
31+
accepted,
32+
})
33+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub(super) fn normalize_feedback_label(label: &str) -> Option<bool> {
2+
match label.trim().to_ascii_lowercase().as_str() {
3+
"accept" | "accepted" => Some(true),
4+
"reject" | "rejected" => Some(false),
5+
_ => None,
6+
}
7+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use crate::server::state::ReviewSession;
2+
3+
use super::super::super::LoadedFeedbackEvalInput;
4+
use super::comment::feedback_comment_from_comment;
5+
6+
pub(in super::super) fn extend_from_review_session(
7+
loaded: &mut LoadedFeedbackEvalInput,
8+
review_id: Option<String>,
9+
session: ReviewSession,
10+
) {
11+
let repo = session
12+
.event
13+
.as_ref()
14+
.and_then(|event| event.github_repo.clone());
15+
let pr_number = session.event.as_ref().and_then(|event| event.github_pr);
16+
let title = session.event.as_ref().and_then(|event| event.title.clone());
17+
18+
loaded.total_reviews_seen += 1;
19+
loaded.total_comments_seen += session.comments.len();
20+
loaded
21+
.comments
22+
.extend(session.comments.into_iter().filter_map(|comment| {
23+
feedback_comment_from_comment(
24+
"review-session",
25+
review_id.clone(),
26+
repo.clone(),
27+
pr_number,
28+
title.clone(),
29+
comment,
30+
)
31+
}));
32+
}

0 commit comments

Comments
 (0)