|
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; |
0 commit comments