Skip to content

Commit

Permalink
[WIP] feat: show list of patches that already have been Reviewed-by
Browse files Browse the repository at this point in the history
Signed-off-by: David Tadokoro <[email protected]>
  • Loading branch information
davidbtadokoro committed Nov 8, 2024
1 parent bb0d654 commit 43d0753
Showing 1 changed file with 97 additions and 26 deletions.
123 changes: 97 additions & 26 deletions src/ui/details_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,6 @@ use crate::app::{screens::details_actions::PatchsetAction, App};
fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, actions_chunk: Rect) {
let patchset_details_and_actions = app.patchset_details_and_actions_state.as_ref().unwrap();

let mut patches_to_reply = String::new();
if let Some(true) = patchset_details_and_actions
.patchset_actions
.get(&PatchsetAction::ReplyWithReviewedBy)
{
patches_to_reply.push('(');
let number_offset = if patchset_details_and_actions.has_cover_letter {
0
} else {
1
};
let patches_to_reply_numbers: Vec<usize> = patchset_details_and_actions
.patches_to_reply
.iter()
.enumerate()
.filter_map(|(i, &val)| if val { Some(i + number_offset) } else { None })
.collect();
for number in patches_to_reply_numbers {
patches_to_reply.push_str(&format!("{number},"));
}
patches_to_reply = format!("{})", &patches_to_reply[..patches_to_reply.len() - 1]);
}

let patchset_details = &patchset_details_and_actions.representative_patch;
let mut patchset_details = vec![
Line::from(vec![
Expand Down Expand Up @@ -72,10 +49,14 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
),
]),
];
if !patches_to_reply.is_empty() {
let reviewed_by = resolve_reviewed_by_detail(app);
if !reviewed_by.is_empty() {
patchset_details.push(Line::from(vec![
Span::styled("Reviewed-by*: ", Style::default().fg(Color::Cyan)),
Span::styled(patches_to_reply, Style::default().fg(Color::DarkGray)),
Span::styled("Reviewed-by: ", Style::default().fg(Color::Cyan)),
Span::styled(
format!("({reviewed_by})"),
Style::default().fg(Color::White),
),
]));
}

Expand Down Expand Up @@ -224,3 +205,93 @@ pub fn keys_hint() -> Span<'static> {
Style::default().fg(Color::Red),
)
}

fn get_reviewed_by_list_from(a: &[usize], b: &[usize]) -> String {
let mut result = String::new();
let mut i = 0;
let mut j = 0;

while i < a.len() || j < b.len() {
match (a.get(i), b.get(j)) {
(Some(&val_a), Some(&val_b)) if val_a == val_b => {
if !result.is_empty() {
result.push(',');
}
result.push_str(&val_a.to_string());
i += 1;
j += 1;
}
(Some(&val_a), Some(&val_b)) if val_a < val_b => {
if !result.is_empty() {
result.push(',');
}
result.push_str(&val_a.to_string());
i += 1;
}
(Some(&_val_a), Some(&val_b)) => {
if !result.is_empty() {
result.push(',');
}
result.push_str(&format!("{}*", val_b));
j += 1;
}
(Some(&val_a), None) => {
if !result.is_empty() {
result.push(',');
}
result.push_str(&val_a.to_string());
i += 1;
}
(None, Some(&val_b)) => {
if !result.is_empty() {
result.push(',');
}
result.push_str(&format!("{}*", val_b));
j += 1;
}
(None, None) => break,
}
}

result
}

fn resolve_reviewed_by_detail(app: &App) -> String {
let patchset_details_and_actions = app.patchset_details_and_actions_state.as_ref().unwrap();

let number_offset = if patchset_details_and_actions.has_cover_letter {
0
} else {
1
};

let mut already_reviewed_by_numbers: Vec<usize> = Vec::new();
if let Some(already_reviewed_by) = app.reviewed_patchsets.get(
&patchset_details_and_actions
.representative_patch
.message_id()
.href,
) {
already_reviewed_by_numbers = already_reviewed_by
.iter()
.cloned()
.map(|i| i + number_offset)
.collect();
already_reviewed_by_numbers.sort_unstable();
}

let mut patches_to_reply_numbers: Vec<usize> = Vec::new();
if let Some(true) = patchset_details_and_actions
.patchset_actions
.get(&PatchsetAction::ReplyWithReviewedBy)
{
already_reviewed_by_numbers.sort_unstable();
patches_to_reply_numbers = patchset_details_and_actions
.patches_to_reply
.iter()
.enumerate()
.filter_map(|(i, &val)| if val { Some(i + number_offset) } else { None })
.collect();
}
get_reviewed_by_list_from(&already_reviewed_by_numbers, &patches_to_reply_numbers)
}

0 comments on commit 43d0753

Please sign in to comment.