use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
use ratatui::text::Line;
use crate::github::detail::PrDetail;
use crate::theme::Palette;
use crate::ui::markdown::render_markdown;
use super::DetailSection;
use super::ThreadIndex;
use super::checks::checks_lines;
use super::comments::build_comments;
use super::commits::build_commits;
use super::files::build_files;
use super::reviews::reviews_lines;
pub(super) fn build_description(
detail: &PrDetail,
p: &Palette,
) -> (Vec<Line<'static>>, Vec<(u16, u16)>) {
let mut lines = Vec::new();
if !detail.body_markdown.is_empty() {
lines.extend(render_markdown(&detail.body_markdown, p));
lines.push(Line::from(""));
}
(lines, Vec::new())
}
pub(super) fn build_checks(
detail: &PrDetail,
p: &Palette,
) -> (Vec<Line<'static>>, Vec<(u16, u16)>) {
if detail.check_runs.is_empty() {
return (Vec::new(), Vec::new());
}
let mut lines = checks_lines(detail, p);
lines.push(Line::from(""));
(lines, Vec::new())
}
pub(super) fn build_reviews(
detail: &PrDetail,
p: &Palette,
) -> (Vec<Line<'static>>, Vec<(u16, u16)>) {
if detail.reviews.is_empty() {
return (Vec::new(), Vec::new());
}
let mut lines = reviews_lines(detail, p);
lines.push(Line::from(""));
(lines, Vec::new())
}
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
pub fn build_section(
section: DetailSection,
detail: &PrDetail,
files_cursor: usize,
files_show_diff: bool,
comments_expanded: bool,
comments_show_outdated: bool,
thread_index: Option<&ThreadIndex>,
expanded_threads: &HashSet<(String, u32)>,
diff_cursor: &RefCell<Option<(String, u32)>>,
scoped_patches: Option<&HashMap<String, Option<String>>>,
commits_cursor: usize,
comments_scope_sha: Option<&str>,
p: &Palette,
ascii: bool,
) -> (Vec<Line<'static>>, Vec<(u16, u16)>) {
match section {
DetailSection::Description => build_description(detail, p),
DetailSection::Checks => build_checks(detail, p),
DetailSection::Reviews => build_reviews(detail, p),
DetailSection::Files => {
let empty_expanded = HashSet::new();
let effective_expanded =
if scoped_patches.is_some() { &empty_expanded } else { expanded_threads };
build_files(
detail,
files_cursor,
files_show_diff,
thread_index,
effective_expanded,
diff_cursor,
scoped_patches,
p,
ascii,
)
}
DetailSection::Comments => build_comments(
detail,
comments_expanded,
comments_show_outdated,
comments_scope_sha,
p,
ascii,
),
DetailSection::Commits => build_commits(detail, p, Some(commits_cursor)),
}
}