Skip to content

Commit 43d0753

Browse files
[WIP] feat: show list of patches that already have been Reviewed-by
Signed-off-by: David Tadokoro <[email protected]>
1 parent bb0d654 commit 43d0753

File tree

1 file changed

+97
-26
lines changed

1 file changed

+97
-26
lines changed

src/ui/details_actions.rs

Lines changed: 97 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,6 @@ use crate::app::{screens::details_actions::PatchsetAction, App};
1111
fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, actions_chunk: Rect) {
1212
let patchset_details_and_actions = app.patchset_details_and_actions_state.as_ref().unwrap();
1313

14-
let mut patches_to_reply = String::new();
15-
if let Some(true) = patchset_details_and_actions
16-
.patchset_actions
17-
.get(&PatchsetAction::ReplyWithReviewedBy)
18-
{
19-
patches_to_reply.push('(');
20-
let number_offset = if patchset_details_and_actions.has_cover_letter {
21-
0
22-
} else {
23-
1
24-
};
25-
let patches_to_reply_numbers: Vec<usize> = patchset_details_and_actions
26-
.patches_to_reply
27-
.iter()
28-
.enumerate()
29-
.filter_map(|(i, &val)| if val { Some(i + number_offset) } else { None })
30-
.collect();
31-
for number in patches_to_reply_numbers {
32-
patches_to_reply.push_str(&format!("{number},"));
33-
}
34-
patches_to_reply = format!("{})", &patches_to_reply[..patches_to_reply.len() - 1]);
35-
}
36-
3714
let patchset_details = &patchset_details_and_actions.representative_patch;
3815
let mut patchset_details = vec![
3916
Line::from(vec![
@@ -72,10 +49,14 @@ fn render_details_and_actions(f: &mut Frame, app: &App, details_chunk: Rect, act
7249
),
7350
]),
7451
];
75-
if !patches_to_reply.is_empty() {
52+
let reviewed_by = resolve_reviewed_by_detail(app);
53+
if !reviewed_by.is_empty() {
7654
patchset_details.push(Line::from(vec![
77-
Span::styled("Reviewed-by*: ", Style::default().fg(Color::Cyan)),
78-
Span::styled(patches_to_reply, Style::default().fg(Color::DarkGray)),
55+
Span::styled("Reviewed-by: ", Style::default().fg(Color::Cyan)),
56+
Span::styled(
57+
format!("({reviewed_by})"),
58+
Style::default().fg(Color::White),
59+
),
7960
]));
8061
}
8162

@@ -224,3 +205,93 @@ pub fn keys_hint() -> Span<'static> {
224205
Style::default().fg(Color::Red),
225206
)
226207
}
208+
209+
fn get_reviewed_by_list_from(a: &[usize], b: &[usize]) -> String {
210+
let mut result = String::new();
211+
let mut i = 0;
212+
let mut j = 0;
213+
214+
while i < a.len() || j < b.len() {
215+
match (a.get(i), b.get(j)) {
216+
(Some(&val_a), Some(&val_b)) if val_a == val_b => {
217+
if !result.is_empty() {
218+
result.push(',');
219+
}
220+
result.push_str(&val_a.to_string());
221+
i += 1;
222+
j += 1;
223+
}
224+
(Some(&val_a), Some(&val_b)) if val_a < val_b => {
225+
if !result.is_empty() {
226+
result.push(',');
227+
}
228+
result.push_str(&val_a.to_string());
229+
i += 1;
230+
}
231+
(Some(&_val_a), Some(&val_b)) => {
232+
if !result.is_empty() {
233+
result.push(',');
234+
}
235+
result.push_str(&format!("{}*", val_b));
236+
j += 1;
237+
}
238+
(Some(&val_a), None) => {
239+
if !result.is_empty() {
240+
result.push(',');
241+
}
242+
result.push_str(&val_a.to_string());
243+
i += 1;
244+
}
245+
(None, Some(&val_b)) => {
246+
if !result.is_empty() {
247+
result.push(',');
248+
}
249+
result.push_str(&format!("{}*", val_b));
250+
j += 1;
251+
}
252+
(None, None) => break,
253+
}
254+
}
255+
256+
result
257+
}
258+
259+
fn resolve_reviewed_by_detail(app: &App) -> String {
260+
let patchset_details_and_actions = app.patchset_details_and_actions_state.as_ref().unwrap();
261+
262+
let number_offset = if patchset_details_and_actions.has_cover_letter {
263+
0
264+
} else {
265+
1
266+
};
267+
268+
let mut already_reviewed_by_numbers: Vec<usize> = Vec::new();
269+
if let Some(already_reviewed_by) = app.reviewed_patchsets.get(
270+
&patchset_details_and_actions
271+
.representative_patch
272+
.message_id()
273+
.href,
274+
) {
275+
already_reviewed_by_numbers = already_reviewed_by
276+
.iter()
277+
.cloned()
278+
.map(|i| i + number_offset)
279+
.collect();
280+
already_reviewed_by_numbers.sort_unstable();
281+
}
282+
283+
let mut patches_to_reply_numbers: Vec<usize> = Vec::new();
284+
if let Some(true) = patchset_details_and_actions
285+
.patchset_actions
286+
.get(&PatchsetAction::ReplyWithReviewedBy)
287+
{
288+
already_reviewed_by_numbers.sort_unstable();
289+
patches_to_reply_numbers = patchset_details_and_actions
290+
.patches_to_reply
291+
.iter()
292+
.enumerate()
293+
.filter_map(|(i, &val)| if val { Some(i + number_offset) } else { None })
294+
.collect();
295+
}
296+
get_reviewed_by_list_from(&already_reviewed_by_numbers, &patches_to_reply_numbers)
297+
}

0 commit comments

Comments
 (0)